Improve exception handling in scheduler