TedStudley / mc-mini

Simple Stokes+Advection/Diffusion solver.
0 stars 4 forks source link

Exception Improvements #30

Closed TedStudley closed 8 years ago

TedStudley commented 8 years ago

Re-worked the exception system to subclass from boost::exception and std::exception The new exception system should be much more robust, as well as allowing us to attach arbitrary information to the exception at the throw site, to be reported when caught.

Added an exception handler in main using boost::diagnostic_information Exception catching/throwing should now give us much more information than before. Compare:

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: <Error> Opening parameter file "foo" failed! Shutting down now.
[1]    96711 abort      ./mc-mini ../exampleParameter

to

/Users/estudley/Workspace/mc-mini/source/parser/parser.cpp(17): Throw in function ParamParser::ParamParser(const string)
Dynamic exception type: boost::exception_detail::clone_impl<RuntimeError>
std::exception::what: Runtime Error
[tag_trace*] = backtrace() returned 5 addresses:
1   mc-mini                             0x000000010980f3ee _ZN11ParamParserC2ENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE + 1582
2   mc-mini                             0x0000000109810cf5 _ZN11ParamParserC1ENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE + 21
3   mc-mini                             0x00000001097d8b91 main + 1521
4   libdyld.dylib                       0x00007fff91bd75fd start + 1

[tag_errmsg*] = Opening parameter file 'foo' failed.

Added support for stack trace in segfault/exception handling: Kinda gave this one away in the new error message example. An uncaught exception should now report the stack trace at the throw site, with at least somewhat decent debugging information. Nice symbols may not be available by default, in which case they should be able to be turned on with the -rdynamic flag.

Updated all pre-existing throws to use the new THROW_WITH_TRACE: All throws (except ones which are planned to be removed in parser.cpp) have been replaced by the new THROW_WITH_TRACE macro, which throws the provided exception after populating its stack trace (and other) information.

Disabled Clang support on TravisCI: The versions of Clang and Boost on TravisCI do not get along with eachother. I've disabled clang compilation on TravisCI for now, since it won't do anything but cause failure spam.

TedStudley commented 8 years ago

Haven't heard any objections in the past week, so I'm merging this in now.

icherkashin commented 8 years ago

I agree: these changes look very useful!