Quote:
Originally posted by cheerios
don't use it, but don't code often in C++ DID find a neat trick thought....
catch(...){
}
is valid, WITH the ...'s. it's a catch-all. laughed my ass off reading that in an intro to C++ book
|
That should actually be a standard practice when using exception handling. It saves your program from 'crashing' with an unhandled exception (an exception that isn't 'caught' before the program exits). And even if you aren't using exception handing, there's nothing saying that someone else using your C++ code won't use it later on, so it's always a good idea to put the
catch( ... ) around the main loop.
i.e.
Quote:
void main( void )
{
try {
while( 1 )
{
// Main loop code
}
}
catch( ... )
{
}
}
|
Another neat trick you can do with exception handing is something like:
Quote:
catch( MyException *e ) {
// some exception handling code
throw e;
}
|
So, in a sense, you 'rethrow' the exception so that it can be caught higher up in the code. And if there are no catch's higher up, then the
catch( ... ) will get it.