A couple questions about catch(...):
1. Is there anything it doesn't catch/stop?
2. Is there any info you can get on the error that happened?
3. Is there a way to do some processing inside that catch block and then rethrow the error?
A couple questions about catch(...):
1. Is there anything it doesn't catch/stop?
2. Is there any info you can get on the error that happened?
3. Is there a way to do some processing inside that catch block and then rethrow the error?
It will catch anything that is catchable. I've seen some things were caught on Windows but not on Solaris with catch (...) - I think it was either divide by 0 or dereferencing a NULL pointer, I don't remember which?
And you can re-throw an exception like this:
Code:catch (...) { throw; }
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
The standard says that catch(...) catches every C++ exception, i.e. everything that was thrown by a throw statement or (in C++0x) by the rethrow_exception() function.
Some implementations unwisely extended this to catch non-C++ exceptions, too.
catch(...) is for two situations:
1) You want to catch everything, do some processing (typically cleanup), and then rethrow. This is usually better achieved using destructors of local objects, but sometimes you have no choice.
2) There's a place where you cannot let exceptions pass. This may be the bottom layer of your application, where you'd rather print a message and continue instead of crashing, or it may be at the interface to some non-C++ code that cannot handle exceptions.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law