From fc667bc8ffe5a2a73d39cfc05e3f403a73bddfac Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 13 Sep 2010 17:04:22 +0200 Subject: Handle option parsing exception --- libcommon/common/common.cxx | 58 ++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 24 deletions(-) (limited to 'libcommon') diff --git a/libcommon/common/common.cxx b/libcommon/common/common.cxx index 4d2d5f0..ed8be69 100644 --- a/libcommon/common/common.cxx +++ b/libcommon/common/common.cxx @@ -24,34 +24,44 @@ using namespace odb; auto_ptr create_database (int argc, char* argv[], size_t max_connections) { + try + { #ifdef DB_ID_MYSQL - cli::argv_file_scanner scan (argc, argv, "--options-file"); - cli::mysql_options ops (scan); + cli::argv_file_scanner scan (argc, argv, "--options-file"); + cli::mysql_options ops (scan); + + if (ops.help ()) + { + cerr << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + cli::mysql_options::print_usage (cerr); + exit (0); + } + + auto_ptr f; - if (ops.help ()) + if (max_connections != 0) + f.reset (new mysql::connection_pool_factory (max_connections)); + + return auto_ptr ( + new mysql::database ( + ops.user (), + ops.password_specified () ? &ops.password () : 0, + ops.database (), + ops.host (), + ops.port (), + ops.socket_specified () ? &ops.socket () : 0, + 0, + f)); +#else + return auto_ptr (0); +#endif + } + catch (const cli::exception& e) { - cerr << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - cli::mysql_options::print_usage (cerr); - exit (0); + cerr << e.what () << endl; + exit (1); } - auto_ptr f; - - if (max_connections != 0) - f.reset (new mysql::connection_pool_factory (max_connections)); - - return auto_ptr ( - new mysql::database ( - ops.user (), - ops.password_specified () ? &ops.password () : 0, - ops.database (), - ops.host (), - ops.port (), - ops.socket_specified () ? &ops.socket () : 0, - 0, - f)); -#else return auto_ptr (0); -#endif } -- cgit v1.1