Catch error and deal with it