terminate called after throwing an instance of 'Poco::SystemException'
anyone knows in what code this uncaught exception is caught?
An uncaught exception is—by definition—not caught anywhere.
If an exception cannot be handled, the C++ exception mechanism will call std::terminate()
(see include header <exception>
), which will call a customizable termination handler. On your platform, the standard termination handler prints the output of std::exception::what()
(which Poco's exceptions inherit from). Unfortunately, the way Poco's exceptions are designed, this will not contain any useful information.
There are multiple ways an exception cannot be handled:
- No suitable
catch()
handler is found and the unwinding mechanism exitsmain()
. You can try wrapping yourmain()
code intry...catch
to print the exception'sdisplayText()
. - A function exits with an exception that does not match its exception specification (
... functionname(...) throw(...)
). This will callstd::unexpected()
which in turn will callstd::terminate()
(by default). - An exception is thrown from within a destructor that is called during the unwinding process of another exception. Never throw exceptions in destructors!
- An exception is thrown while trying to create the original exception object. Never throw exceptions in custom exception classes!
When using Poco threads and a thread is terminated by an unhandled exception, Poco will invoke its internal ErrorHandler
and the program will not exit, so I doubt that this is a threading issue.
Comments
-
Omry Yadan over 3 years
Sometimes (about 1 out of 100 runs), my program terminates with this message:
terminate called after throwing an instance of 'Poco::SystemException' what(): System exception
my code is not the one catching the exception (all my catches are more verbose), and I am not sure where it's caught. it's very likely that the exception does contain a useful message, but it's not returned through the what() method but by the displayText() method.
The string "terminate called after throwing an instance of" has ~600k in Google, so it's probably printed by code inserted by the compiler or by some common library (pthread?). I only seen this error message when the program ran on Linux (never on Windows).
anyone knows in what code this uncaught exception is caught?
-
Omry Yadan over 14 yearsThanks. for easier debugging, I hacked Exception::what() in Poco to print the displayText() to stdout. this makes it possible to see the actual message of uncaught exceptions. I am still working on figuring out the actual cause, the exception is about not being able to lock a mutex, and is probably thrown somehow from some destructor.
-
Omry Yadan over 14 yearsturns out the bug is IN Poco ErrorHandler, or at least one bug. check this out: pocoproject.org/forum/…