Refine error log when handling exception