![]() |
Home | Libraries | People | FAQ | More |
The components of a C++ program may report user-detected errors in several ways, such as via a return value or throwing an exception. System-detected errors such as dereferencing an invalid pointer are reported in other ways, totally operating system and compiler dependent.
Yet many C++ programs, both production and test, must run in an environment where uniform reporting of errors is necessary. For example, converting otherwise uncaught exceptions to non-zero program return codes allows many command line, script, or batch environments to continue processing in a controlled manner. Even some GUI environments benefit from the unification of errors into program return codes.
The Boost.Test Library's Program Execution Monitor (PEM
for short) relieves users from messy error detection and reporting duties by
providing a replacement function main() which calls a user-supplied cpp_main()
function within a monitored environment. The supplied main() then uniformly detects and reports the occurrence
of several types of errors, reducing them to a uniform return code which is
returned to the host environment.
Uniform error reporting is particularly useful for programs running unattended under control of scripts or batch files. Some operating systems pop up message boxes if an uncaught exception occurs, and this requires manual intervention. By converting such exceptions into non-zero program return codes, the library makes the program a better citizen. More uniform reporting of errors isn't a benefit to some programs, particularly programs always run by hand of a knowledgeable person. So the PEM wouldn't be worth using in that environment.
Uniform error reporting can be also useful in test environments such as the Boost regression tests. Be aware though in such case it might be preferable to use the UTF, because it allows one to use the testing tools and generate more detailed error information.