开发者

exception stack trace

开发者 https://www.devze.com 2023-02-05 22:32 出处:网络
regarding th stack trace depth in debug and release mode. I have come to the following conclusion (calling exception.ToString()):

regarding th stack trace depth in debug and release mode. I have come to the following conclusion (calling exception.ToString()):

at debug mode you get the complete stack trace with line numbers (several frames) at release mode instead complete stack trace you get only the throwing method in try block (single frame) with line numbers

  • is that true ? -is there any way to get the complete stack tracve on release mode ?

hello,

I want to log exception details log should include all stack trace (all methods in the chain) log shoud include line numbers of each method in the stack trace.

I have been trying two methods in debug and release mode. I did no like the results:

on debug mode both returns the complete stack trace with line numbers :-) on release mode both returned only the details of catch method. one cant really

know which call in the try block failed

can anyone please explain it ? also, is the stack trace information of excepyion lost when referencing the exception from other method called in the catch block

thanks

option1: exception.ToString-

option2: same results (see below)

        calling static method receving  the exception as parameter 
        System.Diagnostics.StackTrace exceptionStackTrace = 
            new System.Diagnostics.StackTrace(e, true);
        System.Diagnostics.StackFrame [] exceptionStackFrames = 
            exceptionStackTrace.GetFrames();
         foreach (System.Diagnostics.StackFrame stackFrame in exceptionStackFrames)
        {
            message += String.Format("at {0} {1} line {2} column {3} \n",
                stackFrame.GetFileName() == null ? string.Empty : stackFrame.GetFileName(),
                stackFrame.GetMethod().ToString(),
                stackFrame.GetFileL开发者_开发百科ineNumber(),
                stackFrame.GetFileColumnNumber());  
        }


A debug build includes quite a lot more information than a release build, to assist debugging, including things like line numbers.

This information lives in the pdb file - if you are not including these in your released application, you can't get the line numbers in the stack trace.

Follow the instructions on this SO answer to enable line numbers in a release build.

0

精彩评论

暂无评论...
验证码 换一张
取 消