Protection of task destruction on exception and task exit