aboutsummaryrefslogtreecommitdiff
path: root/libcommon
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-09-13 17:04:22 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-09-13 17:04:22 +0200
commitfc667bc8ffe5a2a73d39cfc05e3f403a73bddfac (patch)
treecf5517021567cdf1f9782406cebcc9d5ba5cbe33 /libcommon
parent2e69d645360ca3355341762da2087342b06ac5a8 (diff)
Handle option parsing exception
Diffstat (limited to 'libcommon')
-rw-r--r--libcommon/common/common.cxx58
1 files changed, 34 insertions, 24 deletions
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<database>
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<mysql::connection_factory> f;
- if (ops.help ())
+ if (max_connections != 0)
+ f.reset (new mysql::connection_pool_factory (max_connections));
+
+ return auto_ptr<database> (
+ 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<database> (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<mysql::connection_factory> f;
-
- if (max_connections != 0)
- f.reset (new mysql::connection_pool_factory (max_connections));
-
- return auto_ptr<database> (
- 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<database> (0);
-#endif
}