handling errors using try catch block