|
-
December 27th, 2010, 11:58 PM
#13
Re: Regarding Exception handling
 Originally Posted by Paul McKenzie
See the first reason for a catch to be invoked. I don't know what the inner workings of the C++ SEH switch are, but there is no doubt -- the internal code is issuing a throw.
Again, there are only three reasons why catch() becomes invoked. No other reasons exist.
A lot of programmers believe that the catch() works by magic, and anything wrong with your program falls into the catch. Nothing can be further from the truth -- only thrown exceptions will wind up in catch blocks. Whether all SE's issues a throw, that I don't know. I showed you the code to handle the exception yourself using a handler, and then you throw from there, guaranteeing that your catch() will be invoked.
Regards,
Paul McKenzie
I thought there is two kinds of exceptions. One is simply C++ exception and another one is hardware exception issued by OS such as access violation exception. In your example,
Code:
void foo()
{
try
{
char *p = 0;
*p = 'x';.
}
catch(...)
{
//
}
}
int main()
{
try
{
foo();
}
catch (...)
{
}
}
Obviously this is an access violation exception. So I assume it is issued by OS. Basically first question I have is that in the example above, is it ALWAYS successful to catch this access violation exception since catch block above expects a C++ exception. In order to catch an access violation exception, we must convert the exception above into a C++ exception. Then catch block can always catch such exception. Any comments are welcome! Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|