Deal with errors

wrap the code with try catch