mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 03:55:53 +00:00
129 lines
3.5 KiB
HTML
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 & e)
|
|
{
|
|
cerr << "Bang! " << e.what() << 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 & e)
|
|
{
|
|
cerr << "Oracle error: " << e.err_num_
|
|
<< " " << e.what() << endl;
|
|
}
|
|
catch (soci::exception const & e)
|
|
{
|
|
cerr << "Some other error: " << e.what() << 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 & e)
|
|
{
|
|
cerr << "MySQL error: " << e.err_num_
|
|
<< " " << e.what() << endl;
|
|
}
|
|
catch (soci::exception const & e)
|
|
{
|
|
cerr << "Some other error: " << e.what() << 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 & e)
|
|
{
|
|
cerr << "PostgreSQL error: " << e.sqlstate()
|
|
<< " " << e.what() << endl;
|
|
}
|
|
catch (soci::exception const & e)
|
|
{
|
|
cerr << "Some other error: " << e.what() << 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 © 2004-2013 Maciej Sobczak, Stephen Hutton, Mateusz Loskot</p>
|
|
</body>
|
|
</html>
|