added try catch blocks