Updated code for Exception handling