digitalmars.D.learn - catching Errors in OS callbacks how to print stack trace?
- NaN (30/30) Feb 24 2020 Normally a failed assert gives the file, line number and a stack
- Adam D. Ruppe (6/7) Feb 24 2020 try `writeln(e.toString());` instead.
- NaN (2/9) Feb 24 2020 That worked thanks!
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; } }
Feb 24 2020
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.
Feb 24 2020
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:That worked thanks!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.
Feb 24 2020