All DB-related errors manifest themselves as exceptions of type SOCIError,
which is derived from std::runtime_error.
This allows to
handle database errors within the standard exception framework:
int main()
{
try
{
// regular code
}
catch (exception const &e)
{
cerr << "Bang! " << e.what() << endl;
}
}
Portability note:
The Oracle backend can also throw the instances of the OracleSOCIError,
which is publicly derived from SOCIError and has an
additional public errNum_
member containing the Oracle error code:
int main()
{
try
{
// regular code
}
catch (OracleSOCIError const &e)
{
cerr << "Oracle error: " << e.errNum_
<< " " << e.what() << endl;
}
catch (exception const &e)
{
cerr << "Some other error: " << e.what() << endl;
}
}
| Previous (Library structure, files and compilation) | Next (Connections and simple queries) |
Copyright © 2004-2006 Maciej Sobczak, Stephen Hutton