Catch error and exception (#1431)

Credit goes to @dongm2ez