Top: Exceptions and critical errors

Some of the components in PTypes may produce unrecoverable error conditions, such like a list index is out of bounds, a stream object is constructed with inconsistent parameters, an operation on a stream is requested which requires buffering, etc. These errors are mainly caused by wrong usage of objects or functions of the library.

Whenever an unrecoverable error condition is raised, PTypes calls fatal() with a message describing the error condition and terminates the program. On most platforms this message is being sent to stderr, and on Windows the message is shown in a simple message box.

The function fatal() is declared in <pport.h>.

Some library components also raise recoverable error conditions (exceptions). PTypes only generates exception of type (exception*) defined in <ptypes.h>, or, in some cases, a derivative class, e.g. (estream*). An exception object at least contains an error message which can be retrieved through get_message() method.

NOTE: Exception objects in PTypes are allocated dynamically and therefore, they should be freed by the catch block if it does not pass the exception farther. The exception class is derived from unknown to help you to detect memory leaks in your program. If a thread in a multithreaded application is created using PTypes thread class, then all PTypes exceptions thrown in each thread are being caught and freed automatically (unless caught in the user code).

See also streams Error handling and Examples.

PTypes home