添加try catch 原理注释
This commit is contained in:
@@ -37,8 +37,8 @@
|
||||
// // 封装函数用来调用实际的槽函数
|
||||
// static void test_slot_caller(void* args) {
|
||||
// test_slot_args* a = args;
|
||||
// printf("test_slot_caller: %d %d\n", a->a, a->b);
|
||||
// printf("args_p=%p\n", a);
|
||||
// DBG_LOG("test_slot_caller: %d %d\n", a->a, a->b);
|
||||
// DBG_LOG("args_p=%p\n", a);
|
||||
// test_slot(a->self, a->a, a->b);
|
||||
// }
|
||||
|
||||
@@ -104,18 +104,18 @@ static void mdelay(unsigned long mSec){
|
||||
|
||||
// 定义槽函数
|
||||
slot test_slot(test_sig_obj2* obj, int a, int b) {
|
||||
printf("test_slot var=%d\n", obj->test_var);
|
||||
DBG_LOG("test_slot var=%d\n", obj->test_var);
|
||||
obj->test_var = a + b;
|
||||
printf("test_slot var=%d\n", obj->test_var);
|
||||
DBG_LOG("test_slot var=%d\n", obj->test_var);
|
||||
}
|
||||
|
||||
slot test_slot3(test_sig_obj3* obj, int a, int b) {
|
||||
printf("test_slot3 a=%d, b=%d\n", a, b);
|
||||
printf("obj->v1=%d, obj->v2=%d\n", obj->test_var, obj->test_var2);
|
||||
DBG_LOG("test_slot3 a=%d, b=%d\n", a, b);
|
||||
DBG_LOG("obj->v1=%d, obj->v2=%d\n", obj->test_var, obj->test_var2);
|
||||
}
|
||||
|
||||
slot test_slot3_2(test_sig_obj3* obj, int a, int b, const char* c) {
|
||||
printf("test_slot3_2 a=%d, b=%d, c=%s\n", a, b, c);
|
||||
DBG_LOG("test_slot3_2 a=%d, b=%d, c=%s\n", a, b, c);
|
||||
throw_("test_slot3_2 err");
|
||||
}
|
||||
|
||||
@@ -123,9 +123,32 @@ static test_sig_obj g_sig_obj = { .test_var = 1, };
|
||||
static test_sig_obj2 g_sig_obj2 = { .test_var = 2, };
|
||||
static test_sig_obj3 g_sig_obj3;
|
||||
|
||||
|
||||
|
||||
void try_catch_test() {
|
||||
try_ {
|
||||
DBG_LOG("进入第一个try");
|
||||
DBG_LOG("抛出异常");
|
||||
throw_("第一个try抛出的异常");
|
||||
}catch_ {
|
||||
DBG_LOG("进入第一个catch");
|
||||
try_ {
|
||||
DBG_LOG("进入第二个try");
|
||||
throw_("第二个try抛出的异常");
|
||||
}catch_ {
|
||||
DBG_LOG("进入第二个catch");
|
||||
throw_("第二个catch抛出的异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int thread_fun(void* t) {
|
||||
mythread_t* th = sigthread_init("signal_thread");
|
||||
printf("thread_fun start\n");
|
||||
DBG_LOG("thread_fun start\n");
|
||||
connect(&g_sig_obj, test_signal, th, &g_sig_obj2, test_slot);
|
||||
connect(&g_sig_obj, test_signal, th, &g_sig_obj3, test_slot3);
|
||||
connect(&g_sig_obj, test_signal2, th, &g_sig_obj3, test_slot3_2);
|
||||
@@ -134,8 +157,8 @@ int thread_fun(void* t) {
|
||||
mdelay(1000);
|
||||
emit test_signal2(&g_sig_obj, 5, 6,"hello world");
|
||||
mdelay(1000);
|
||||
printf("test end\n");
|
||||
throw_("my err");
|
||||
DBG_LOG("test end\n");
|
||||
try_catch_test();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -104,15 +104,15 @@ int thread_fun(void* t)
|
||||
tmp[i] = bitmap[i];
|
||||
}
|
||||
ret = gpio_find_first_int((uint8_t*)tmp, sizeof(tmp), 0);
|
||||
printf("ret=%d\n", ret - 1);
|
||||
DBG_LOG("ret=%d\n", ret - 1);
|
||||
ret = gpio_find_first_int((uint8_t*)tmp, sizeof(tmp), ret);
|
||||
printf("ret=%d\n", ret - 1);
|
||||
DBG_LOG("ret=%d\n", ret - 1);
|
||||
|
||||
for (int i = 0;i < sizeof(bitmap) / sizeof(bitmap[0]);i++) {
|
||||
tmp[i] = bitmap[i];
|
||||
}
|
||||
ret = iot_bitmap_ffs_from((uint8_t*)tmp, sizeof(tmp), 0);
|
||||
printf("ret=%d\n", ret - 1);
|
||||
DBG_LOG("ret=%d\n", ret - 1);
|
||||
ret = iot_bitmap_ffs_from((uint8_t*)tmp, sizeof(tmp), ret);
|
||||
printf("ret=%d\n", ret - 1);
|
||||
DBG_LOG("ret=%d\n", ret - 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user