Files
rippled/doc/errors.html
Vinnie Falco 9708a12607 Squashed 'src/soci/' content from commit 6e9312c
git-subtree-dir: src/soci
git-subtree-split: 6e9312c4bb3748907bd28d62c40feca42878cfef
2015-03-18 19:36:00 -07:00

129 lines
3.5 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>SOCI - errors</title>
</head>
<body>
<p class="banner">SOCI - The C++ Database Access Library</p>
<h2>Errors</h2>
<p>All DB-related errors manifest themselves as exceptions of type <code>soci_error</code>,
which is derived from <code>std::runtime_error</code>.<br />
This allows to
handle database errors within the standard exception framework:</p>
<pre class="example">
int main()
{
try
{
// regular code
}
catch (std::exception const &amp; e)
{
cerr &lt;&lt; "Bang! " &lt;&lt; e.what() &lt;&lt; endl;
}
}
</pre>
<div class="note">
<p><span class="note">Portability note:</span></p>
<p>The Oracle backend can also throw the instances of the <code>oracle_soci_error</code>,
which is publicly derived from <code>soci_error</code> and has an
additional public <code>err_num_</code>
member containing the Oracle error code:</p>
<pre class="example">
int main()
{
try
{
// regular code
}
catch (soci::oracle_soci_error const &amp; e)
{
cerr &lt;&lt; "Oracle error: " &lt;&lt; e.err_num_
&lt;&lt; " " &lt;&lt; e.what() &lt;&lt; endl;
}
catch (soci::exception const &amp; e)
{
cerr &lt;&lt; "Some other error: " &lt;&lt; e.what() &lt;&lt; endl;
}
}
</pre>
</div>
<div class="note">
<p><span class="note">Portability note:</span></p>
<p>The MySQL backend can throw instances of the <code>mysql_soci_error</code>,
which is publicly derived from <code>soci_error</code> and has an
additional public <code>err_num_</code>
member containing the MySQL error code (as returned by
<code>mysql_errno()</code>):</p>
<pre class="example">
int main()
{
try
{
// regular code
}
catch (soci::mysql_soci_error const &amp; e)
{
cerr &lt;&lt; "MySQL error: " &lt;&lt; e.err_num_
&lt;&lt; " " &lt;&lt; e.what() &lt;&lt; endl;
}
catch (soci::exception const &amp; e)
{
cerr &lt;&lt; "Some other error: " &lt;&lt; e.what() &lt;&lt; endl;
}
}
</pre>
</div>
<div class="note">
<p><span class="note">Portability note:</span></p>
<p>The PostgreSQL backend can also throw the instances of the <code>postgresql_soci_error</code>,
which is publicly derived from <code>soci_error</code> and has an
additional public <code>sqlstate()</code>
member function returning the five-character "SQLSTATE" error code:</p>
<pre class="example">
int main()
{
try
{
// regular code
}
catch (soci::postgresql_soci_error const &amp; e)
{
cerr &lt;&lt; "PostgreSQL error: " &lt;&lt; e.sqlstate()
&lt;&lt; " " &lt;&lt; e.what() &lt;&lt; endl;
}
catch (soci::exception const &amp; e)
{
cerr &lt;&lt; "Some other error: " &lt;&lt; e.what() &lt;&lt; endl;
}
}
</pre>
</div>
<table class="foot-links" border="0" cellpadding="2" cellspacing="2">
<tr>
<td class="foot-link-left">
<a href="installation.html">Previous (Installation)</a>
</td>
<td class="foot-link-right">
<a href="connections.html">Next (Connections and simple queries)</a>
</td>
</tr>
</table>
<p class="copyright">Copyright &copy; 2004-2013 Maciej Sobczak, Stephen Hutton, Mateusz Loskot</p>
</body>
</html>