C++ exceptions

This section describes the programming considerations for coding C++ exceptions in your application on the z/TPF system.

The z/TPF system supports only application-defined exceptions. System errors and program checks are handled by the operating system and are not shown to the application.

Exceptions can be thrown from a function and caught by another function in the same CSO; for example, an exception can be thrown by a CSO, but caught by another CSO that resides in the ECB program nesting level (PNL). All z/TPF programs that reside in the PNL between the current program and the program that contains a catch clause are dropped from the nesting level. z/TPF enter/back processing performs all cleanup that is associated with dropping a program from a nesting level.

If an application throws an exception and there is no corresponding catch clause to handle the exception, the standard behavior for the libstdc++ runtime library (CPP1) is to call the terminate function. The default action of the terminate function is to call the abort function, which raises the SIGABRT signal. However, the terminate function that is used by the z/TPF system calls the tpf_abort function to issue the 94204 system error. Upon return from the system error, the tpf_abort function calls the standard abort function to raise the SIGABRT signal and force the ECB to exit. You can take one of the following actions for an unhandled exception:
  • If you do not want the z/TPF system to issue a system error for an unhandled exception, create a local modification of the cabort.c program that omits the serrc_op_ext call.
  • If you want your application to process unhandled exceptions, set up your own terminate handler function by using the set_terminate function. For example, you can create the myterminate function and then register the myterminate function by calling std::set_terminate(myterminate).

If you code a throw block in a destructor, the corresponding try and catch blocks must also be in the scope of the destructor or the results are unpredictable.