Learning to read and understand stack trace makes debugging less painful as well as makes you a better programmer by solving the exceptions quickly instead of spending hours!
4. 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
5. • 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
6. 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
8. 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
10. 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
11. 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?