Exception Handling


All Foundation 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 classes provided in Foundation toolkits are listed below.

To detect and recover from errors in any Recursion Software toolkit, you must use C++ try...catch blocks in your code. Failure to catch an exception will result in the global function uncaught_exception() to be invoked, 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 if an unexpected error condition is encountered.

The following code fragment illustrates several techniques for handling errors in Recursion Software ToolKits.

try
  {
  // Allocate a thread specific data (TSD) key.
  os_thread_key_t key = os_this_thread::allocate();

  // assume an exception was thrown - this code never executes.
  cout << "key = " << key << endl;
  }
catch ( os_thread_toolkit_error& error )
  {
  // This will catch an error generated by a Thread<ToolKit> object.
  cout << "Caught error: " << error.what() << endl;
  }
catch ( os_time_toolkit_error& error )
  {
  // This will catch an error generated by a Time<ToolKit> 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.