473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Try-catch works with structured exception

Hello everyone,
I have tested try-catch works with structured exception, to my
surprise. Previously I think we have to use __try and __except.

Any comments? Here is my test code and I am using Visual Studio 2008.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int* address = NULL;
  8.  
  9. try{
  10.  
  11. (*address) = 1024;
  12. } catch (...)
  13. {
  14. cout << "access violation caught" << endl;
  15. }
  16. return 0;
  17. }
  18.  

thanks in advance,
George
Jan 22 '08 #1
3 1987
George2 wrote:
Hello everyone,
I have tested try-catch works with structured exception, to my
surprise. Previously I think we have to use __try and __except.

Any comments? Here is my test code and I am using Visual Studio 2008.
This is not portable. It may work with VS 2008. In general, it makes
little sense to catch an access violation, a signal is much more
interesting since you may actually be able to do something interesting -
like mapping memory to the location or whatever.

There are a whole lot of reasons you may get an accvio or segmentation
fault, very few of which you can continue with anything sensible.

In some cases, a divide by zero or other arithmetic fault may be
interesting to catch. I think that gcc has a way of catching those, you
need to recompile your arithmetic code with some compiler flag.
>
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int* address = NULL;
  6.     try{
  7.         (*address) = 1024;
  8.     } catch (...)
  9.     {
  10.         cout << "access violation caught" << endl;
  11.     }
  12.     return 0;
  13. }
  14.  


thanks in advance,
George
Jan 22 '08 #2
George2 wrote:
Hello everyone,
I have tested try-catch works with structured exception, to my
surprise. Previously I think we have to use __try and __except.

Any comments? Here is my test code and I am using Visual Studio
2008.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int* address = NULL;
  6. try{
  7. (*address) = 1024;
  8. } catch (...)
  9. {
  10. cout << "access violation caught" << endl;
  11. }
  12. return 0;
  13. }
  14.  
That's a known bug in MS' exception handling. A catch(...) statement
should only pick up things that are thrown.

http://www.thunderguy.com/semicolon/...tion-handling/
With VS2008 you can presumably select bug or no-bug with the proper
compiler switches.
Bo Persson
Jan 22 '08 #3
George2 wrote:
Hello everyone,
I have tested try-catch works with structured exception, to my
surprise. Previously I think we have to use __try and __except.

Any comments? Here is my test code and I am using Visual Studio 2008.
Actually, that works as far back as Visual Studio 6. The question,
though, is what one would do with such an exception, since once caught
in this fashion you can't (I don't think) get any further information...

--
Mike Smith
Jan 28 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Erlend Fuglum | last post by:
Hi everyone, I'm having some trouble sorting lists. I suspect this might have something to do with locale settings and/or character encoding/unicode. Consider the following example, text...
12
by: Brian Kelley | last post by:
def res(): try: a = 1 return finally: print "do I get here?" res() outputs "do I get here?"
1
by: Askari | last post by:
Hi, In my program (too long for cut-paste) : http://www.cvm.qc.ca/9974331/Temp/crypte.py When I run and click on the button "Crypter!", a thread is run for the method "def crypte():" (line...
9
by: David Stockwell | last post by:
In referring to my copy of the python bible, it tells me I can't use all three items 'try' except and finally. I can use the t/f or t/e combinations though What combination can i use if i want...
26
by: djw | last post by:
Hi, Folks- I have a question regarding the "proper" use of try: finally:... Consider some code like this: d = Device.open() try: d.someMethodThatCanRaiseError(...) if SomeCondition: raise...
40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
4
by: wk6pack | last post by:
Hi, I was wondering why when I declare the dim variable outside the try statement, I could use the .dispose() function but when I declare it inside the try statement, I get Name 'varname' is not...
2
by: BarrySearle | last post by:
# Is this valid (or is excp local to try/except)? try: try: doSomething1 excp = 0 except: excp = 1 #endTry if (_excp_): doSomething1 # is excp defined here? excp = 0
3
by: Sori Schwimmer | last post by:
Hi, I think that would be useful to have an improved version of the "try" statement, as follows: try(retrys=0,timeout=0): # things to try except: # what to do if failed
3
try
by: HMS Surprise | last post by:
I read in the ref man that try-except-finally did not work in earlier versions, I am using jython 2.2. Does this imply that try-except without finally does not work either? I get a syntax error on...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.