浏览代码

prevent false positive with multiple catchs wrt exc_call_handler trigger

ncannasse 6 年之前
父节点
当前提交
2da143af11
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      src/std/error.c

+ 3 - 1
src/std/error.c

@@ -88,6 +88,7 @@ HL_PRIM void hl_throw( vdynamic *v ) {
 	hl_thread_info *t = hl_get_thread();
 	hl_thread_info *t = hl_get_thread();
 	hl_trap_ctx *trap = t->trap_current;
 	hl_trap_ctx *trap = t->trap_current;
 	bool was_rethrow = false;
 	bool was_rethrow = false;
+	bool call_handler = false;
 	if( t->exc_flags & HL_EXC_RETHROW ) {
 	if( t->exc_flags & HL_EXC_RETHROW ) {
 		was_rethrow = true;
 		was_rethrow = true;
 		t->exc_flags &= ~HL_EXC_RETHROW;
 		t->exc_flags &= ~HL_EXC_RETHROW;
@@ -95,13 +96,14 @@ HL_PRIM void hl_throw( vdynamic *v ) {
 		t->exc_stack_count = capture_stack_func(t->exc_stack_trace, HL_EXC_MAX_STACK);
 		t->exc_stack_count = capture_stack_func(t->exc_stack_trace, HL_EXC_MAX_STACK);
 	t->exc_value = v;
 	t->exc_value = v;
 	t->trap_current = trap->prev;
 	t->trap_current = trap->prev;
+	call_handler = (t->exc_flags&HL_EXC_CATCH_ALL) || trap == t->trap_uncaught || t->trap_current == NULL;
 	if( (t->exc_flags&HL_EXC_CATCH_ALL) || break_on_trap(t,trap,v) ) {
 	if( (t->exc_flags&HL_EXC_CATCH_ALL) || break_on_trap(t,trap,v) ) {
 		if( trap == t->trap_uncaught ) t->trap_uncaught = NULL;
 		if( trap == t->trap_uncaught ) t->trap_uncaught = NULL;
 		t->exc_flags |= HL_EXC_IS_THROW;
 		t->exc_flags |= HL_EXC_IS_THROW;
 		hl_debug_break();
 		hl_debug_break();
 		t->exc_flags &= ~HL_EXC_IS_THROW;
 		t->exc_flags &= ~HL_EXC_IS_THROW;
-		if( t->exc_handler && !was_rethrow ) hl_dyn_call(t->exc_handler,&v,1);
 	}
 	}
+	if( t->exc_handler && call_handler ) hl_dyn_call(t->exc_handler,&v,1);
 	if( throw_jump == NULL ) throw_jump = longjmp;
 	if( throw_jump == NULL ) throw_jump = longjmp;
 	throw_jump(trap->buf,1);
 	throw_jump(trap->buf,1);
 }
 }