Thread overview | |||||
---|---|---|---|---|---|
|
February 24, 2020 catching Errors in OS callbacks how to print stack trace? | ||||
---|---|---|---|---|
| ||||
Normally a failed assert gives the file, line number and a stack trace, but I hit one today that just prints.. assertion failure Im sure it is because it's in the WindowProc callback from the OS. As the callback is nothrow you need to catch and handle anything there, you have to catch all throwables or else it just hangs when you hit an assert. But how do I get it to print the full file, line, and stack trace? Here's my window proc... extern(Windows) LRESULT WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) nothrow { try { auto window = cast(Window) (cast(void*) GetWindowLongPtr(hwnd, 0)); if (window is null) return DefWindowProcA(hwnd, msg, wparam, lparam); else return window.windowProc(msg, wparam, lparam); } catch (Throwable e) { try { writeln(e.msg); } catch(Exception what) {} PostQuitMessage(0); return 0; } } |
February 24, 2020 Re: catching Errors in OS callbacks how to print stack trace? | ||||
---|---|---|---|---|
| ||||
Posted in reply to NaN | On Monday, 24 February 2020 at 13:42:01 UTC, NaN wrote:
> try { writeln(e.msg); }
try `writeln(e.toString());` instead.
msg only contains the message passed to the constructor by itself, toString includes the file/line and stack trace members too.
easiest way usually.
|
February 24, 2020 Re: catching Errors in OS callbacks how to print stack trace? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Monday, 24 February 2020 at 13:43:30 UTC, Adam D. Ruppe wrote:
> On Monday, 24 February 2020 at 13:42:01 UTC, NaN wrote:
>> try { writeln(e.msg); }
>
> try `writeln(e.toString());` instead.
>
> msg only contains the message passed to the constructor by itself, toString includes the file/line and stack trace members too.
>
> easiest way usually.
That worked thanks!
|
Copyright © 1999-2021 by the D Language Foundation