common: make DESTRUCTOR_CATCHALL macro really exception safe

Console.Error() can trigger some exceptions (like out of memory)

v2:
Add a default fallback catch(...) in case someone badly add a new
exception in the codebase
This commit is contained in:
Gregory Hainaut 2015-09-23 09:22:29 +02:00
parent 2eb73644e9
commit 927dd827ce
1 changed files with 16 additions and 4 deletions

View File

@ -29,16 +29,28 @@ void pxTrap();
// exception. Use this macro to dispose of these dangerous exceptions, and generate a
// friendly error log in their wake.
//
// Note: Console can also fire an Exception::OutOfMemory
#define __DESTRUCTOR_CATCHALL( funcname ) \
catch( BaseException& ex ) \
{ \
Console.Error( "Unhandled BaseException in %s (ignored!):", funcname ); \
Console.Error( ex.FormatDiagnosticMessage() ); \
try { \
Console.Error( "Unhandled BaseException in %s (ignored!):", funcname ); \
Console.Error( ex.FormatDiagnosticMessage() ); \
} catch (...) { \
fprintf(stderr, "ERROR: (out of memory?)\n"); \
} \
} \
catch( std::exception& ex ) \
{ \
Console.Error( "Unhandled std::exception in %s (ignored!):", funcname ); \
Console.Error( ex.what() ); \
try { \
Console.Error( "Unhandled std::exception in %s (ignored!):", funcname ); \
Console.Error( ex.what() ); \
} catch (...) { \
fprintf(stderr, "ERROR: (out of memory?)\n"); \
} \
} \
catch(...) { \
/* Unreachable code */ \
}
#define DESTRUCTOR_CATCHALL __DESTRUCTOR_CATCHALL( __pxFUNCTION__ )