Fix to call function if error is caught