SOCI Logo Get SOCI at SourceForge.net. Fast, secure and Free Open Source software downloads

SOCI - Errors

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;
    }
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
SourceForge Logo

Generated on Sun Oct 3 2010 17:42:17 for EXTRAS-SOCI by Doxygen 1.7.1