Fixed detection of the exception type