Monday, April 11, 2011

Missing StackTrace Information

I seem to be missing some information from my stack trace, here is what i'm getting:

at Foo.Bar(DataTable table) in D:\Foo\Bar\authoring\App_Code\FooBar.vb:line 87

Where is the rest of the stack trace infomation?

EDIT:

Custom errors in the Web.Config is set to off, i'm handling the error where it's caught like this:

 Catch ex As Exception
     Respose.Write(ex.StackTrace)
 End Try

The Stack Trace is still getting truncated.

From stackoverflow
  • Make sure customErrors is set to "RemoteOnly" or "Off" in your web.config to disable friendly errors.

    Or possibly stack trace getting reset? (Although if this was the case you still should see something)

    Will reset your stack trace.

    catch(Exception ex) 
    {
       throw ex; 
    }
    

    Will NOT reset your stack trace.

    catch(Exception ex) 
    {
       throw; 
    }
    

    EDIT:

    ex.StackTrace gets the current stack. The stacktrace starts where the exception was thrown(error happens) and ends at the current stack frame where the exception is caught. So it is reversing the call stack. Since you are writing out stacktrace as soon as it happens it doesn't get a chance to go any further up the callstack.

    Depending on what you are doing you can try a few things.

    //To just see the stackTrace
    Catch ex As Exception
         Throw
     End Try
    

    Environment.StackTrace - Gets current stack trace information

    //If you are trying to log the stacktrace 
    Catch ex As Exception
         Respose.Write(Environment.StackTrace)
         Respose.Write(ex.StackTrace)
     End Try
    
    //If is hiding then try - hiding as in throw ex vs just throw
    Catch ex As Exception
         //careful innerException can be null
         //so need to check before using it
         Respose.Write(ex.InnerException)
     End Try
    

    One of those methods should work for you.

0 comments:

Post a Comment