Soprano  2.9.4
Error handling in Soprano

Soprano tries to simulate exceptions through the usage of Soprano::Error::ErrorCache.

Most methods in Soprano classes have a means of reporting if an operation was successful or not. For additional error information they inherit Soprano::Error::ErrorCache which provides the method Soprano::Error::ErrorCache::lastError().

Thus, advanced error handling would look as follows:

* Soprano::Statement invalidStatement;
* if( model->addStatement( invalidStatement ) != Error::ErrorNone ) {
* showErrorMessage( model->lastError().message() );
* }
*

For methods that do not return an immediate error status, Soprano::Error::Error evaluates to a boolean. Thus, one can easily check if an error occurred as follows:

* while( it.next() ) {
* doSomething( *it );
* }
* if( it.lastError() ) {
* displayError( "Iteration failed: " + it.lastError().message() );
* }
*

This has the same effect as checking for Soprano::Error::ErrorNone.

This error handling is thread-safe. Thus, two threads can for example call methods of one Model at the same time and still get proper Soprano::Error::Error instances back.