From 927dd827ce4bafea6725fd8d34770a5f8320dacf Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Wed, 23 Sep 2015 09:22:29 +0200 Subject: [PATCH] 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 --- common/include/Utilities/Exceptions.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/common/include/Utilities/Exceptions.h b/common/include/Utilities/Exceptions.h index 34cfa5fad8..635564e336 100644 --- a/common/include/Utilities/Exceptions.h +++ b/common/include/Utilities/Exceptions.h @@ -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__ )