Improve exception handling for debug