int wmain(int argc, uchar *argv[]) { #else int main(int argc, char *argv[]) { #endif hl_trap_ctx ctx; vdynamic *exc; hl_global_init(&ctx); hl_setup_exception(hlc_resolve_symbol,hlc_capture_stack); hl_setup_callbacks(hlc_static_call, hlc_get_wrapper); hl_sys_init((void**)(argv + 1),argc - 1); hl_trap(ctx, exc, on_exception); # ifdef HL_VCC __try { # endif hl_entry_point(); # ifdef HL_VCC } __except( throw_handler(GetExceptionCode()) ) {} # endif hl_global_free(); return 0; on_exception: { varray *a = hl_exception_stack(); int i; uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(exc)); for(i=0;i<a->size;i++) uprintf(USTR("Called from %s\n"), hl_aptr(a,uchar*)[i]); hl_debug_break(); } hl_global_free(); return 1; }
HL_PRIM void *hl_fatal_error( const char *msg, const char *file, int line ) { hl_blocking(true); # ifdef HL_WIN_DESKTOP HWND consoleWnd = GetConsoleWindow(); DWORD pid; GetWindowThreadProcessId(consoleWnd, &pid); if( consoleWnd == NULL || GetActiveWindow() != NULL || GetCurrentProcessId() == pid ) MessageBoxA(NULL,msg,"Fatal Error", MB_OK | MB_ICONERROR); # endif printf("%s(%d) : FATAL ERROR : %s\n",file,line,msg); hl_blocking(false); hl_debug_break(); exit(1); return NULL; }
HL_PRIM void hl_throw( vdynamic *v ) { hl_thread_info *t = hl_get_thread(); hl_trap_ctx *trap = t->trap_current; bool was_rethrow = false; bool call_handler = false; if( t->exc_flags & HL_EXC_RETHROW ) { was_rethrow = true; t->exc_flags &= ~HL_EXC_RETHROW; } else t->exc_stack_count = capture_stack_func(t->exc_stack_trace, HL_EXC_MAX_STACK); t->exc_value = v; 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( trap == t->trap_uncaught ) t->trap_uncaught = NULL; t->exc_flags |= HL_EXC_IS_THROW; hl_debug_break(); t->exc_flags &= ~HL_EXC_IS_THROW; } if( t->exc_handler && call_handler ) hl_dyn_call(t->exc_handler,&v,1); if( throw_jump == NULL ) throw_jump = longjmp; throw_jump(trap->buf,1); HL_UNREACHABLE; }
HL_PRIM HL_NO_OPT void hl_assert() { hl_debug_break(); hl_error("assert"); }
HL_PRIM HL_NO_OPT void hl_breakpoint() { hl_debug_break(); }