digitalmars.D.learn - Stack trace
Could someone please tell me how can I get the stack trace when
an exception is thrown? My test code:
Code: -------------------------------------------------
void f1() {
throw new Exception("in f1");
}
void f2() {
f1();
}
void f3() {
f2();
}
void main() {
f3();
}
Output: -------------------------------------------------
$ rdmd t.d
object.Exception t.d(5): in f1
----------------
0x0040BC6C
0x0040BAF7
0x00402045
0x0040264E
0x00402251
0x00402074
0x754D33AA in BaseThreadInitThunk
0x76F09EF2 in RtlInitializeExceptionChain
0x76F09EC5 in RtlInitializeExceptionChain
----------------
I am expecting function names instead of some hex codes.
Thank you in advance.
Jun 12 2013
Ahh, looks like the stack trace is supported only in debug mode. -g option made the exception to spit out the function names. $ rdmd -g t.d object.Exception t.d(5): in f1 ---------------- 0x0040CC9C in char[][] core.sys.windows.stacktrace.StackTrace.trace() 0x0040CB27 in core.sys.windows.stacktrace.StackTrace core.sys.windows.stacktrace.StackTrace.__ctor() 0x0040204C in void t.f1() at C:\test\t.d(6) 0x00402058 in void t.f2() at C:\test\t.d(10) 0x00402064 in void t.f3() at C:\test\t.d(14) 0x00402070 in _Dmain at C:\test\t.d(17) 0x00402BD8 in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runMain() 0x00402C0E in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).void runAll() 0x00402811 in _d_run_main 0x00402128 in main 0x754D33AA in BaseThreadInitThunk 0x76F09EF2 in RtlInitializeExceptionChain 0x76F09EC5 in RtlInitializeExceptionChain ----------------
Jun 12 2013








"New guy" <yahoo yahoo.com>