generalize exception handling