added exception handling for whole main function