Initial version of exception handling
Added exception handling in the main function