|
-
December 27th, 2010, 11:09 PM
#12
Re: Regarding Exception handling
 Originally Posted by LarryChen
Here is an example from you,
Code:
void foo()
{
try
{
char *p = 0;
*p = 'x';.
}
catch(...)
{
//
}
}
int main()
{
try
{
foo();
}
catch (...)
{
}
}
In the try block of function foo, no throw is thrown. So you think catch never catches any exception?
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
Last edited by Paul McKenzie; December 27th, 2010 at 11:14 PM.
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
|