terminate called after throwing an instance of 'Poco::SystemException'
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开发者_如何学C only seen this error message when the program ran on Linux (never on Windows).
anyone knows in what code this uncaught exception is caught?
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.
I was getting the same error. I had used a try catch block in the run function of the Poco::Runnable class. I removed the try catch block from this class and used a derivative of Poco::ErrorHandler class to handle the errors. After this I stopped getting this error.
精彩评论