mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 10:09:36 +02:00
added poco_unexpected() macro invoking Bugcheck::unexpected() to deal with unexpected exceptions in destructors
This commit is contained in:
@@ -33,8 +33,8 @@ namespace Poco {
|
|||||||
class Foundation_API Bugcheck
|
class Foundation_API Bugcheck
|
||||||
/// This class provides some static methods that are
|
/// This class provides some static methods that are
|
||||||
/// used by the
|
/// used by the
|
||||||
/// poco_assert_dbg(), poco_assert(), poco_check_ptr()
|
/// poco_assert_dbg(), poco_assert(), poco_check_ptr(),
|
||||||
/// and poco_bugcheck() macros.
|
/// poco_bugcheck() and poco_unexpected() macros.
|
||||||
/// You should not invoke these methods
|
/// You should not invoke these methods
|
||||||
/// directly. Use the macros instead, as they
|
/// directly. Use the macros instead, as they
|
||||||
/// automatically provide useful context information.
|
/// automatically provide useful context information.
|
||||||
@@ -56,6 +56,12 @@ public:
|
|||||||
/// An internal error was encountered. Break into the debugger, if
|
/// An internal error was encountered. Break into the debugger, if
|
||||||
/// possible, then throw an BugcheckException.
|
/// possible, then throw an BugcheckException.
|
||||||
|
|
||||||
|
static void unexpected(const char* file, int line);
|
||||||
|
/// An exception was caught in a destructor. Break into debugger,
|
||||||
|
/// if possible and report exception. Must only be called from
|
||||||
|
/// within a catch () block as it rethrows the exception to
|
||||||
|
/// determine its class.
|
||||||
|
|
||||||
static void debugger(const char* file, int line);
|
static void debugger(const char* file, int line);
|
||||||
/// An internal error was encountered. Break into the debugger, if
|
/// An internal error was encountered. Break into the debugger, if
|
||||||
/// possible.
|
/// possible.
|
||||||
@@ -97,6 +103,10 @@ protected:
|
|||||||
|
|
||||||
#define poco_bugcheck_msg(msg) \
|
#define poco_bugcheck_msg(msg) \
|
||||||
Poco::Bugcheck::bugcheck(msg, __FILE__, __LINE__)
|
Poco::Bugcheck::bugcheck(msg, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
|
||||||
|
#define poco_unexpected() \
|
||||||
|
Poco::Bugcheck::unexpected(__FILE__, __LINE__);
|
||||||
|
|
||||||
|
|
||||||
#define poco_debugger() \
|
#define poco_debugger() \
|
||||||
|
|||||||
@@ -57,6 +57,35 @@ void Bugcheck::bugcheck(const char* msg, const char* file, int line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Bugcheck::unexpected(const char* file, int line)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::string msg("Caught exception in destructor: ");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Poco::Exception& exc)
|
||||||
|
{
|
||||||
|
msg += exc.displayText();
|
||||||
|
}
|
||||||
|
catch (std::exception& exc)
|
||||||
|
{
|
||||||
|
msg += exc.what();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
msg += "unknown exception";
|
||||||
|
}
|
||||||
|
Debugger::enter(msg, file, line);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Bugcheck::debugger(const char* file, int line)
|
void Bugcheck::debugger(const char* file, int line)
|
||||||
{
|
{
|
||||||
Debugger::enter(file, line);
|
Debugger::enter(file, line);
|
||||||
@@ -78,6 +107,4 @@ std::string Bugcheck::what(const char* msg, const char* file, int line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
Reference in New Issue
Block a user