Optimize exception handling