Exception Handling |
All Recursion Software toolkits
use the ANSI/ISO C++ exception mechanism to report errors. Each toolkit has a
specialized error class that it uses to encapsulate the problem details. The
exception class provided in Platform<ToolKit> for UNIX is os_unix_toolkit_error
. This represents an error condition in Platform<ToolKit>
for UNIX.
To detect and recover from errors
in any Recursion Software toolkit, you must place C++ try...catch
blocks in your code. Failure to catch an exception invokes the global function uncaught_exception()
, usually followed by a call to terminate() . Both
of these global functions are included in your compiler's C++ runtime library
and are not part of any Recursion Software toolkit. The call to terminate()
forces your application to abort and is unrecoverable. It is usually better to
provide your own exception handler that safely shuts down your application in
case an unexpected error condition is encountered.
The following code fragment illustrates several techniques for handling errors in Recursion Software toolkits.
try
{
// Sleep for three seconds.
os_this_process::sleep( 3 );
// assume an exception was thrown - this code never executes.
cout << "awake" << endl;
}
catch ( os_unix_toolkit_error& error )
{
// This will catch an error generated by a
// Platform<ToolKit> for UNIX object.
cout << "Caught error: " << error.what() << endl;
}
catch ( os_toolkit_error& error )
{
// This will catch any error generated by an Recursion Software ToolKit,
// excluding the ANSI/ISO components found in Standards<ToolKit>.
cout << "Caught error: " << error.what() << endl;
}
catch ( ... )
{
// This catch block will handle any thrown exception, although
// you are not able to query any information about it. This is
// often used as a "last resort" to keep your application from
// crashing abnormally.
}
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.