Add try catch block to handle exceptions