Improve exception handling in main.cpp

Related to issue #188