Generalize the exception trap