Soprano  2.8.0
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::Model* model = Soprano::createModel();
 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:

 Soprano::StatementIterator it = model->listStatements();
 while( ) {
    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.