My dsPIC processor supports error trap interrupts such as divide by zero, memory access violation, etc.
If one of these occurs then it is likely the task currently running has caused it. I would like to avoid a complete processor reset and just end the appropriate task. So, I will need to get the task pointer of the currently running task and terminate it. So, the code would look something like this:
void div_zero_exception()
{
xTaskHandle tp = xTaskGetCurrentTaskHandle();
_debug_msg("[****] Task terminated: %s due to zero division", pcTaskGetTaskName(tp));
vTaskSuspend(tp);
}
This will run from the task that is being terminated - would this cause any problems? This also only suspends the task - ideally, it would be completely terminated and all memory related to the task would be freed.
One concern I would have is that you don't know for sure that the exception is coming from a task, it could also be coming from an interrupt handler. You also need to be careful about is killing a task at an unknown point, as you have no Idea on the status of the resources it uses.
I would also be very nervous about using a "printf" like function at the exception level. Note that in the exception handler, ALL interrupts are disabled.