Exception Handling


The Database toolkit uses the ANSI/ISO C++ exception mechanism to report errors. The toolkit has a specialized error class that it uses to encapsulate the problem details. The exception classes provided in Database toolkit is 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
  {
  // Try to connect to the db server on our own machine
  os_ip_address iaddr( os_host::my_host().name() );
  os_db_connection connection1( os_socket_address( iaddr, 3006) );

  }
catch ( os_db_error& error )
  {
  // This will catch an error generated by a Database<ToolKit> object.
  cout << "Caught database error:" << endl;
  cout << "\t" << error.description( error.get_code() ) << endl;
  cout << "\t" << error.what() << endl;
  cout << "Native Error Code: " << error.get_native() << endl;
  }
catch ( os_streaming_toolkit_error& error )
  {
  // This will catch an error generated by a Streaming<ToolKit> object.
  // Streaming<ToolKit> objects are used by the Database<ToolKit>
  cout << "Caught streaming error:" << endl;
  cout << "\t" << error.description( error.code() ) << endl;
  cout << "\t" << error.what() << endl;
  cout << "Native Error Code: " << error.native() << endl;
  }
catch ( os_network_toolkit_error& error )
  {
  // This will catch an error generated by a Network<ToolKit> object.
  // Network<ToolKit> objects are used by the Database<ToolKit>
  cout << "Caught streaming error:" << endl;
  cout << "\t" << error.description( error.code() ) << endl;
  cout << "\t" << error.what() << endl;
  cout << "Native Error Code: " << error.native() << 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©2005-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.