How to read
Stack Trace ?
Jinal Patel
Agenda
• Anatomy of StackTrace
• Strategies to solve any Exception
• Case scenarios – nested error, running tests
• Conclusion
Namespace / assembly Class Method
Filename path : Line Number
What is Stack Trace?
• works on the "call stack," which is a data structure (FILO – First In
Last Out) that provides information about the current subroutine of
the program being debugged.
• Call stack – the stack of the functions that were called up to that
point
• When you call a function, the system sets aside space in memory
for that function to do the necessary work. -> that’s called stack
frames
• More than one function’s stack frame exist in
memory at a given time.
• If P1() -> P2() -> P3() ->P4(), all four have
open frames but only one frame in control
• These frames are arranged on stack.
• When new function is called, new frame is
pushed onto the top of stack and becomes
active frame.
• The Frame for the most recently called
function is always on the top of the stack.
• When function finish the work , frame is
popped of the stack, frame immediately
below it becomes the new , active, function
on top
Strategy to solve any Exception
Step 1 :Get rid of Noise!
- Stack of stuff inside the same library – unnecessary
- Lot of lines which is not yours
- External Codes
Noise !!!
Nested Error
System.Exception
Message=Didn't you learn math in grade 1? Division by zero is not possible!
Source=ConsoleApp3
StackTrace:
at ConsoleApp3.Program.MoreStuff() in C:UsersJinal
PatelsourcereposConsoleApp3ConsoleApp3Program.cs:line 27
at ConsoleApp3.Program.DoStuff() in C:UsersJinal
PatelsourcereposConsoleApp3ConsoleApp3Program.cs:line 14
at ConsoleApp3.Program.Main(String[] args) in C:UsersJinal
PatelsourcereposConsoleApp3ConsoleApp3Program.cs:line 9
This exception was originally thrown at this call stack:
ConsoleApp3.Program.MoreStuff() in Program.cs
Inner Exception 1:
DivideByZeroException: Attempted to divide by zero.
at ConsoleApp3.Program.MoreStuff() in C:UsersJinal
PatelsourcereposConsoleApp3ConsoleApp3Program.cs:line 22
Running Tests Cause of Error
at Line 149
Test failed!
Debug Mode
Strategy to solve any Exception
• Step 2: What went wrong? - > Find theories around the exception
• Step 3: Test your theories
- Fix locally
- Break it the same way by login
- Divide the LOC into smaller chunks
Conclusion
Where did it break?
Where did you call it?
How did you get there?
Why did it happen? (theories)
How can you test that?

How to read stack trace in c#

  • 1.
    How to read StackTrace ? Jinal Patel
  • 2.
    Agenda • Anatomy ofStackTrace • Strategies to solve any Exception • Case scenarios – nested error, running tests • Conclusion
  • 3.
    Namespace / assemblyClass Method Filename path : Line Number
  • 4.
    What is StackTrace? • works on the "call stack," which is a data structure (FILO – First In Last Out) that provides information about the current subroutine of the program being debugged. • Call stack – the stack of the functions that were called up to that point • When you call a function, the system sets aside space in memory for that function to do the necessary work. -> that’s called stack frames
  • 5.
    • More thanone function’s stack frame exist in memory at a given time. • If P1() -> P2() -> P3() ->P4(), all four have open frames but only one frame in control • These frames are arranged on stack. • When new function is called, new frame is pushed onto the top of stack and becomes active frame. • The Frame for the most recently called function is always on the top of the stack. • When function finish the work , frame is popped of the stack, frame immediately below it becomes the new , active, function on top
  • 6.
    Strategy to solveany Exception Step 1 :Get rid of Noise! - Stack of stuff inside the same library – unnecessary - Lot of lines which is not yours - External Codes
  • 7.
  • 8.
    Nested Error System.Exception Message=Didn't youlearn math in grade 1? Division by zero is not possible! Source=ConsoleApp3 StackTrace: at ConsoleApp3.Program.MoreStuff() in C:UsersJinal PatelsourcereposConsoleApp3ConsoleApp3Program.cs:line 27 at ConsoleApp3.Program.DoStuff() in C:UsersJinal PatelsourcereposConsoleApp3ConsoleApp3Program.cs:line 14 at ConsoleApp3.Program.Main(String[] args) in C:UsersJinal PatelsourcereposConsoleApp3ConsoleApp3Program.cs:line 9 This exception was originally thrown at this call stack: ConsoleApp3.Program.MoreStuff() in Program.cs Inner Exception 1: DivideByZeroException: Attempted to divide by zero. at ConsoleApp3.Program.MoreStuff() in C:UsersJinal PatelsourcereposConsoleApp3ConsoleApp3Program.cs:line 22
  • 9.
    Running Tests Causeof Error at Line 149 Test failed! Debug Mode
  • 10.
    Strategy to solveany Exception • Step 2: What went wrong? - > Find theories around the exception • Step 3: Test your theories - Fix locally - Break it the same way by login - Divide the LOC into smaller chunks
  • 11.
    Conclusion Where did itbreak? Where did you call it? How did you get there? Why did it happen? (theories) How can you test that?