optimize exception handling