diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-11-28 20:36:13 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-11-28 20:36:13 +0000 |
commit | 3cc17cac971f3b1785713246b5824c0a26396aa1 (patch) | |
tree | ed4126a7d53a30862d90c64ca3a90ed2a19ffebd | |
parent | Rename types.* to avoid name clashes (diff) | |
download | libdbpp-3cc17cac971f3b1785713246b5824c0a26396aa1.tar.bz2 libdbpp-3cc17cac971f3b1785713246b5824c0a26396aa1.tar.xz libdbpp-3cc17cac971f3b1785713246b5824c0a26396aa1.zip |
Gracefully handle execution failures during the setup phases.
-rw-r--r-- | libdbpp/createMockDb.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libdbpp/createMockDb.cpp b/libdbpp/createMockDb.cpp index 960f848..8e2dffe 100644 --- a/libdbpp/createMockDb.cpp +++ b/libdbpp/createMockDb.cpp @@ -10,6 +10,19 @@ namespace fs = boost::filesystem; void emptyHandler(int) { } +void createFailHandler() +{ + try { + if (auto eptr = std::current_exception()) { + std::rethrow_exception(eptr); + } + } + catch (const std::exception & e) { + std::cerr << "Failed to create mock database\n" << e.what() << std::endl; + } + exit(1); +} + int main(int argc, char ** argv) { @@ -39,9 +52,11 @@ main(int argc, char ** argv) } po::notify(vm); + std::set_terminate(createFailHandler); std::cout << "Creating database..."; auto mock = DB::MockDatabaseFactory::createNew(connector, master, database, scripts); std::cout << " done." << std::endl; + std::set_terminate(nullptr); if (!drop) { std::cout << "Done. ctrl+c to tear down and exit." << std::endl; |