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() );
}
virtual Error lastError() const
QString message() const
A Model is the central class in Soprano. It is a queryable collection of RDF quadruples,...
Definition model.h:95
virtual Error::ErrorCode addStatement(const Statement &statement)=0
A Statement instance represents one RDF quadruple.
Definition statement.h:48
SOPRANO_EXPORT Model * createModel(const BackendSettings &settings=BackendSettings())

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() );
}
virtual StatementIterator listStatements(const Statement &partial) const =0
An iterator that provides a stream of Statements.

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.