Enhanced error logging during exception