Tuesday, 15 April 2014

c# - Exceptions lose part of stacktrace in try/catch context -



c# - Exceptions lose part of stacktrace in try/catch context -

i have 2 examples. in first case, debugger catches unhandled exception:

static void main(string[] args) { exec(); } static void exec() { throw new exception(); }

and exception has total stacktrace:

@ consoleapplication28.program.exec() @ consoleapplication28.program.main(string[] args) @ system.appdomain._nexecuteassembly(runtimeassembly assembly, string[] args) @ system.appdomain.executeassembly(string assemblyfile, evidence assemblysecurity, string[] args) @ microsoft.visualstudio.hostingprocess.hostproc.runusersassembly() @ system.threading.threadhelper.threadstart_context(object state) @ system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state) @ system.threading.threadhelper.threadstart()

the sec case:

static void main(string[] args) { exec(); } static void exec() { seek { throw new exception(); } grab (exception ex) { } // breakpoint }

at breakpoint exception has short stacktrace:

@ consoleapplication28.program.exec()

why stacktraces cutting containing method in sec case, , how prevent it? need total stacktrace bugreports, otherwise it's not possible find there problem is, without total stacktrace.

what you're seeing in visual studio debugger unhandled exception visual studio hosting process trapping (ie after first 2 stack frames part of vs "host plumbing"). if disable hosting process (project properties->enable visual studio hosting process), you'll see "short" stack trace in both scenarios (notwithstanding won't see stack frame main in sec case because exception "handled", not allowed propagate main). shorter stack trace stack trace see if running application outside debugger.

the stack works imagine - each method phone call pushes stack frame onto it, , @ end of method stack frame "popped", or removed stack. stack trace see on exception composed of stack frames frame exception thrown, frame exception handled, stack "unwound".

c# .net exception exception-handling stack-trace

No comments:

Post a Comment