Fix erroneous exception handling