Sophie

Sophie

distrib > Fedora > 13 > x86_64 > media > updates > by-pkgid > fc669c0115c2f74e1d26807f2cb98f7a > files > 807

soprano-apidocs-2.5.2-1.fc13.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Soprano: Error handling in Soprano</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.1 -->
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="navpath">
    <ul>
      <li><a class="el" href="index.html">Soprano (aka QRDF) - A modular RDF storage framework</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<h1>Error handling in <a class="el" href="namespaceSoprano.html">Soprano</a> </h1>  </div>
</div>
<div class="contents">
<p>Soprano tries to simulate exceptions through the usage of <a class="el" href="classSoprano_1_1Error_1_1ErrorCache.html" title="Core class of Soprano&#39;s exception system.">Soprano::Error::ErrorCache</a>.</p>
<p>Most methods in Soprano classes have a means of reporting if an operation was successful or not. For additional error information they inherit <a class="el" href="classSoprano_1_1Error_1_1ErrorCache.html" title="Core class of Soprano&#39;s exception system.">Soprano::Error::ErrorCache</a> which provides the method <a class="el" href="classSoprano_1_1Error_1_1ErrorCache.html#a3251b8052cdf932d59a523ca215d21c9">Soprano::Error::ErrorCache::lastError()</a>.</p>
<p>Thus, advanced error handling would look as follows:</p>
<div class="fragment"><pre class="fragment"> <a class="code" href="classSoprano_1_1Model.html" title="A Model is the central class in Soprano. It is a queryable collection of RDF quadruples, i.e statements.">Soprano::Model</a>* model = <a class="code" href="namespaceSoprano.html#a66f765cf9fd9aae07f874fdb8867dd1c">Soprano::createModel</a>();
 <a class="code" href="classSoprano_1_1Statement.html" title="A Statement instance represents one RDF quadruple.">Soprano::Statement</a> invalidStatement;
 <span class="keywordflow">if</span>( model-&gt;<a class="code" href="classSoprano_1_1Model.html#aed5b923235288fbac997850cca8f6053">addStatement</a>( invalidStatement ) != Error::ErrorNone ) {
    showErrorMessage( model-&gt;<a class="code" href="classSoprano_1_1Error_1_1ErrorCache.html#a3251b8052cdf932d59a523ca215d21c9">lastError</a>().message() );
 }
</pre></div><p>For methods that do not return an immediate error status, <a class="el" href="classSoprano_1_1Error_1_1Error.html" title="Represents an error in Soprano.">Soprano::Error::Error</a> evaluates to a boolean. Thus, one can easily check if an error occurred as follows:</p>
<div class="fragment"><pre class="fragment"> <a class="code" href="classSoprano_1_1StatementIterator.html" title="An iterator that provides a stream of Statements.">Soprano::StatementIterator</a> it = model-&gt;<a class="code" href="classSoprano_1_1Model.html#a7f50dc6483e0bed7830877182c7906ac">listStatements</a>();
 <span class="keywordflow">while</span>( it.<a class="code" href="classSoprano_1_1Iterator.html#a1ba632f6f015242ab9441da77d48415b">next</a>() ) {
    doSomething( *it );
 }
 <span class="keywordflow">if</span>( it.<a class="code" href="classSoprano_1_1Error_1_1ErrorCache.html#a3251b8052cdf932d59a523ca215d21c9">lastError</a>() ) {
    displayError( <span class="stringliteral">&quot;Iteration failed: &quot;</span> + it.<a class="code" href="classSoprano_1_1Error_1_1ErrorCache.html#a3251b8052cdf932d59a523ca215d21c9">lastError</a>().message() );
 }
</pre></div><p>This has the same effect as checking for <a class="el" href="namespaceSoprano_1_1Error.html#aef1bd25c5b6705951735e0fb5c5ff525a69f521a4f40b463680d393963d5b4187">Soprano::Error::ErrorNone</a>.</p>
<p>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 <a class="el" href="classSoprano_1_1Error_1_1Error.html" title="Represents an error in Soprano.">Soprano::Error::Error</a> instances back. </p>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Thu Oct 21 2010 for Soprano by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>