Improved exception handling in task manager.