473,406 Members | 2,713 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,406 software developers and data experts.

Try-catch works with structured exception

200 100+
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
4 1670
weaknessforcats
9,208 Expert Mod 8TB
Windows only supports structured exception handling (SEH). Your C++ try/catch/throw are really compiled as __try/__except/throw. The throw os a call to RaiseException(). In this case an access violation by attempting to reach outside your process address space.

Since this is a Win32 exception, you can catch these as an int so you can lookup the error.

However, if you actually write a __try/__except/throw youcan field the exception in the __except block and after admonishing whoever is responsible you could EXCEPTION__CONTINUE_EXECUTION and keep your program alive. Visual Studio does not make this flag available in a C++ catch block.
Jan 22 '08 #2
George2
200 100+
Thanks weaknessforcats,


Interesting reply. Two more comments,

1.

Windows only supports structured exception handling (SEH). Your C++ try/catch/throw are really compiled as __try/__except/throw. The throw os a call to RaiseException(). In this case an access violation by attempting to reach outside your process address space.
How do you know try/catch is compiled as __try/__except? Any macro definitions make this true or?

2.

However, if you actually write a __try/__except/throw youcan field the exception in the __except block and after admonishing whoever is responsible you could EXCEPTION__CONTINUE_EXECUTION and keep your program alive. Visual Studio does not make this flag available in a C++ catch block.
Sorry, for my limited knowledge, I do not quite understand what do you mean "EXCEPTION__CONTINUE_EXECUTION and keep your program alive", at least I have never seen and used EXCEPTION__CONTINUE_EXECUTION in Visual Studio. Any more description or show some pseudo code please?


regards,
George
Jan 23 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
I just posted a URL on another thread that should cover this.
Jan 23 '08 #4
George2
200 100+
Thanks weaknessforcats,


I will read it further. :-)

I just posted a URL on another thread that should cover this.

regards,
George
Jan 25 '08 #5

Sign in to post your reply or Sign up for a free account.

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.