[Cppcms-users] Trying cppdb connection & catch exceptions
Brought to you by:
artyom-beilis
|
From: augustin <aug...@ov...> - 2012-05-26 06:01:38
|
Hello Artyom and all,
I wish to test my DB connection (e.g. to check that the connection string is
working), and catch any exception arising.
Here is the code:
// Testing that the connection string actually allows us to connect to
the DB.
try {
cppdb::session sql(connection_string);
}
//catch (std::exception const &e) {
catch (cppdb::cppdb_error const& e) {
_bInit_db = false;
return;
}
However, when the connection string is wrong, the application crashes
altogether:
cppdb::mysql::Access denied for user 'WRONG'@'localhost' (using password: YES)
How to test the DB connection and gracefully handle failed DB connections?
Thanks,
Augustin.
--
Friends: http://www.reuniting.info/
My projects:
http://astralcity.org/ http://lesenjeux.fr/ http://linux.overshoot.tv/
http://overshoot.tv/ http://charityware.info/ http://masquilier.org/
http://openteacher.info/ http://minguo.info/ http://jacqueslemaire.fr/
http://www.wechange.org/ http://searching911.info/
.
|