Re: [Cppcms-users] Trying cppdb connection & catch exceptions
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-05-26 22:13:42
|
----- Original Message ----- > From: augustin <aug...@ov...> > To: cpp...@li... > Cc: > Sent: Saturday, May 26, 2012 8:36 AM > Subject: [Cppcms-users] Trying cppdb connection & catch exceptions > > 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? > Are you sure it crashes altogether? Because try { cppdb::session sql(connection_string); } catch (cppdb::cppdb_error const& e) { // fail } // ok Should work. If it does not can you create a small example that reproduces the problem. Because the scheme above works for me 100% > Thanks, > > Augustin. > Artyom |