add try catch to the main function

Set M.ErrorWhileLoadingApplication to false if an error occurs