more robust exception handler implementation