程序为
#include <math.h> #include <stdlib.h> #define MIN_VALUE (1e-4) #define IS_DOUBLE_ZERO(d) (abs(d) < MIN_VALUE) double div_func(double x, double y) { if (IS_DOUBLE_ZERO(y)) { throw y; /* throw exception */ } return x / y; } void throw_exceptions(void *args) { try { div_func(6, 3); rt_kprintf("there is no err\n"); div_func(4, 0); /* create exception*/ rt_kprintf("you can run here\n"); } catch(double) /* catch exception */ { rt_kprintf("error of dividing zero\n"); } } MSH_CMD_EXPORT(throw_exceptions, throw cpp exceptions);
运行时报错为
\ | / - RT - Thread Operating System / | \ 4.0.3 build Nov 17 2020 2006 - 2020 Copyright by rt-thread team RTT Control Block Detection Address is 0x200024b0 msh >throw_exceptions there is no err thread:tshell abort!
void abort(void)
{
if (rt_thread_self())
{
rt_thread_t self = rt_thread_self();
rt_kprintf("thread:%-8.*s abort!\n", RT_NAME_MAX, self->name);
rt_thread_suspend(self);
rt_schedule();
}
while (1);
}
请问如何操作啊?