Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 only seen this error message when the program ran on Linux (never on Windows).

anyone knows in what code this uncaught exception is caught?

like image 732
Omry Yadan Avatar asked Nov 19 '09 11:11

Omry Yadan


1 Answers

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 exits main(). You can try wrapping your main() code in try...catch to print the exception's displayText().
  • A function exits with an exception that does not match its exception specification (... functionname(...) throw(...)). This will call std::unexpected() which in turn will call std::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.

like image 161
Ferdinand Beyer Avatar answered Oct 05 '22 16:10

Ferdinand Beyer