updated with try catch block