Skip to content

Conversation

@TechnicalFowl
Copy link
Contributor

This adds a default UnhandledExceptionFilter to the stdlib for win32. This will be called when an exception (such as a seg fault) reaches the top-level unhandled exception filter and the application is not being debugged. Currently the application will just silently die in these cases necessitating breaking out the debugger but this will report a convenient backtrace.

It also registers a panic function to allow it to track if a panic has occurred to prevent it double reporting these when the panic function calls $$trap().

Example:

import std::io;

fn void main()
{
    io::printfn("Foo");
    uint* p = (uint*) 0x13370;
    *p = 0;
    io::printfn("Bar");
}

Previous output:

Foo

New output:

Foo

ERROR: 'Access Violation at address 0x7ff6fe370f8a'
  in main (C:\Data\test\src\main.c3:52) [C:\Data\test\build\test.exe]
  in _$main (C:\Data\test\src\main.c3:47) [C:\Data\test\build\test.exe]
  in invoke_main (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78) [C:\Data\test\build\test.exe]
  in __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) [C:\Data\test\build\test.exe]
  in __scrt_common_main (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:330) [C:\Data\test\build\test.exe]
  in mainCRTStartup (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:16) [C:\Data\test\build\test.exe]
  in BaseThreadInitThunk (source unavailable) [C:\WINDOWS\System32\KERNEL32.DLL]
  in RtlUserThreadStart (source unavailable) [C:\WINDOWS\SYSTEM32\ntdll.dll]

@TechnicalFowl TechnicalFowl force-pushed the win32_exception_handler branch from 53a61b5 to 22b2552 Compare November 3, 2025 05:07
@lerno
Copy link
Collaborator

lerno commented Nov 3, 2025

Thank you!

@lerno lerno merged commit d438d75 into c3lang:master Nov 3, 2025
3 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants