import core.thread;
void fun()
{
throw new Exception("hi");
}
void main()
{
Thread thread = new Thread(&fun);
thread.start();
thread.join();
}
The following program rethrows the exception at join() call as documented, but the attached debugger (Visual Studio debugger in this case) should be able to catch it and break at the line where it was originally thrown.
In a similar Windows C++ program, a thread created with either CreateThread or _beginthread[ex], given a function which throws an std::exception, does indeed trigger a debug break at the throw site. Only exception to this is std::thread, which causes the program to abort on the exception instead of hitting debug break.
A side note to exception handling on Windows systems, there should be more information provided to debugger about the caught exceptions (namely the type and the message) when debugger catches the exception, but in this particular case, all the information printed in debugger output is that an unknown exception was caught with no strack trace information. I understand Visual Studio debugger does not support D exceptions, but with the current state in debugging support, we should have at least the name and the message of the exception given to debugger in some manner (with OutputDebugMessage?). I have tried to work around this problem by using custom exceptions which calls OutputDebugMessage to display this information and while it works, it's a hack and does not work with exceptions thrown by druntime.
Comment #1 by r.sagitario — 2019-08-30T15:40:22Z
The mago debugger extension now prints the type, location and message for unhandled exceptions that are caught by the debugger.
It doesn't do this for handled exceptions as a non-standard exception mechanism is used by dmd for Win64 (LDC uses C++ exceptions, so can stop on throw). Win32 should work as expected.
Comment #2 by robert.schadek — 2024-12-07T13:38:51Z