Fixed an error code check in exception handling