All DB-related errors manifest themselves as exceptions of type soci_error,
which is derived from std::runtime_error.
This allows to
handle database errors within the standard exception framework:
int main() {
try {
// regular code
} catch (std::exception const & e) {
std::cerr << "Bang! " << e.what() << std::endl;
}
}
Portability note:
The Oracle backend can also throw the instances of the oracle_soci_error,
which is publicly derived from soci_error and has an
additional public err_num_
member containing the Oracle error code:
int main() {
try {
// regular code
} catch (soci::oracle_soci_error const & e) {
std::cerr << "Oracle error: " << e.err_num_
<< " " << e.what() << std::endl;
} catch (std::exception const & e) {
std::cerr << "Some other error: " << e.what()
<< std::endl;
}
}
Portability note:
The MySQL backend can throw instances of the mysql_soci_error,
which is publicly derived from soci_error and has an
additional public err_num_
member containing the MySQL error code (as returned by
mysql_errno()):
int main() {
try {
// regular code
} catch (soci::mysql_soci_error const & e) {
std::cerr << "MySQL error: " << e.err_num_
<< " " << e.what() << std::endl;
} catch (std::exception const & e) {
std::cerr << "Some other error: " << e.what()
<< std::endl;
}
}
| Previous (Library structure, files and compilation) | Next (Connections and simple queries) |
Copyright © 2004-2008 Maciej Sobczak, Stephen Hutton
Generated on Sun Oct 3 2010 17:42:17 for EXTRAS-SOCI by Doxygen 1.7.1