Catch error event rather than catch block