| Start |
|---|
| Stack trace for a simple NullReferenceException in Windows Forms Let's create a small piece of code that throws an exception: If we execute this, we get the following Exception and stack trace: The stack trace goes on like that, but this part will suffice for our purposes. At the top of the stack trace we see the line: at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in F:\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 29 This is the most important part. It tells us the exact line where the Exception occurred: line 29 in Form1.cs . The second line is at System.Windows.Forms.Control.OnClick(EventArgs e) This is the method that called We can continue like this; the third line is at System.Windows.Forms.Button.OnClick(EventArgs e) This is, in turn, the code that called The stack trace is the list of functions that was called until your code encountered the Exception. And by following this, you can figure out which execution path your code followed until it ran into trouble! Note that the stack trace includes calls from the .Net system; you don't normally need to follow all Microsofts So, why is this called a "stack trace"? So the stack lets the computer know where it left off, before calling a new method. But it also serves as a debugging help. Like a detective tracing the steps that a criminal took when committing their crime, a programmer can use the stack to trace the steps a program took before it crashed. |
Read Article
https://develop.horje.com/learn/1434/reference