From a51b7ec4faf7eae30588aad29e8979e3cd8b4678 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Oct 2009 04:07:06 -0400 Subject: Construct global_scope object within the exception handler --- src/main.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/main.cc') diff --git a/src/main.cc b/src/main.cc index 9f0e8690..0aec8886 100644 --- a/src/main.cc +++ b/src/main.cc @@ -76,11 +76,13 @@ int main(int argc, char * argv[], char * envp[]) ::textdomain("ledger"); #endif - // Create the session object, which maintains nearly all state relating to - // this invocation of Ledger; and register all known journal parsers. - std::auto_ptr global_scope(new global_scope_t(envp)); + std::auto_ptr global_scope; try { + // Create the session object, which maintains nearly all state relating to + // this invocation of Ledger; and register all known journal parsers. + global_scope.reset(new global_scope_t(envp)); + global_scope->session().set_flush_on_next_data_file(true); // Construct an STL-style argument list from the process command arguments @@ -181,7 +183,11 @@ int main(int argc, char * argv[], char * envp[]) } } catch (const std::exception& err) { - global_scope->report_error(err); + if (global_scope.get()) + global_scope->report_error(err); + else + std::cerr << "Exception during initialization: " << err.what() + << std::endl; } catch (int _status) { status = _status; // used for a "quick" exit, and is used only -- cgit v1.2.3