473,387 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Understanding the Stack Trace

While working with ASP.NET I've sometimes encountered errors in my applications, but I've always known exactly why I'm getting the error and have been able to fix it. So I've never needed to understand the Stack Trace, but I want to understand the stack trace so can somebody please explain it to me or point me to something that will

Thanks
Jeremy
Nov 18 '05 #1
3 24465
Basically, the Stack Trace is a trace of function calls that go on the
Stack. When a program runs, it copies functions from the Heap to the Stack,
in a "Stack" (so to speak) which is a stack of the functions. When a
function is called, a copy of it is put on the Stack to execute. When a
function exits, it is pulled from the Stack. If it calls other functions,
these are stacked on top of it, and each one is pulled off the Stack when it
exits.

The Stack Trace shows the "topmost" (latest) functions called. It helps
identify the chain of execution that led up to the current situation
(usually an exception). It identifies each function on the Stack in the
order (reversed) in which they appear, with the last one executed at the
top.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Jeremy" <an*******@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...
While working with ASP.NET I've sometimes encountered errors in my applications, but I've always known exactly why I'm getting the error and
have been able to fix it. So I've never needed to understand the Stack
Trace, but I want to understand the stack trace so can somebody please
explain it to me or point me to something that will?
Thanks,
Jeremy

Nov 18 '05 #2
Kevin has a great technical explanation, so I will go to an analogy.

First, let's understand why the word Stack is applicable. Let's imagine a
deck of cards and you are playing solitaire. As you get to cards you cannot
play, you add them to the discard pile (or stack). Each card is stacked on
top of another one.

To equate to programming, Card1 (the first card on the discard pile) calls 2
which calls 3. You cannot finish working with card 1 until you have played
card 2 and card 3 (and so on). This would be like function Card1() calling
function Card2(), which calls function Card3. If you break inside the
Card3() function, you have a stack like so:

Card3
Card2
Card1

Now, let's say Card3 returns an answer that Card2 processes, and Card2 has
an error. The stack now looks like so:

Card2
Card1

In the stack trace, you will see Card2 with a line number and Card1 with a
line number, if you have the IDE set to break on all errors, or if you let
the error remain when deployed and do not have a Try ... Catch to handle the
error.

Sometimes what you do in your code does not throw an exception until it hits
the .NET Framework components. In these cases, you often have to look down
the stack until you hit your own functions to determine what actually caused
the error.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Jeremy" <an*******@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...
While working with ASP.NET I've sometimes encountered errors in my applications, but I've always known exactly why I'm getting the error and
have been able to fix it. So I've never needed to understand the Stack
Trace, but I want to understand the stack trace so can somebody please
explain it to me or point me to something that will?
Thanks,
Jeremy

Nov 18 '05 #3
Kevin has a great technical explanation, so I will go to an analogy.

First, let's understand why the word Stack is applicable. Let's imagine a
deck of cards and you are playing solitaire. As you get to cards you cannot
play, you add them to the discard pile (or stack). Each card is stacked on
top of another one.

To equate to programming, Card1 (the first card on the discard pile) calls 2
which calls 3. You cannot finish working with card 1 until you have played
card 2 and card 3 (and so on). This would be like function Card1() calling
function Card2(), which calls function Card3. If you break inside the
Card3() function, you have a stack like so:

Card3
Card2
Card1

Now, let's say Card3 returns an answer that Card2 processes, and Card2 has
an error. The stack now looks like so:

Card2
Card1

In the stack trace, you will see Card2 with a line number and Card1 with a
line number, if you have the IDE set to break on all errors, or if you let
the error remain when deployed and do not have a Try ... Catch to handle the
error.

Sometimes what you do in your code does not throw an exception until it hits
the .NET Framework components. In these cases, you often have to look down
the stack until you hit your own functions to determine what actually caused
the error.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Jeremy" <an*******@discussions.microsoft.com> wrote in message
news:7A**********************************@microsof t.com...
While working with ASP.NET I've sometimes encountered errors in my applications, but I've always known exactly why I'm getting the error and
have been able to fix it. So I've never needed to understand the Stack
Trace, but I want to understand the stack trace so can somebody please
explain it to me or point me to something that will?
Thanks,
Jeremy

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Andy Fish | last post by:
Hi, in my c# code I have something like this: try { ... } catch (Exception ex) { ... throw ex; }
3
by: Mike Schilling | last post by:
Instances of SystemOutOfMemoryException do not contain a stack trace. Easy test to verify this: class OOM { public static void Main() { try { Object arr = new Object; } catch...
0
by: Mike Schilling | last post by:
I have some code that calls methods reflectively (the method called and its parameters are determined by text received in a SOAP message, and I construct a map from strings to MethodInfos). The...
2
by: Lasse Vågsæther Karlsen | last post by:
If I got the following code: try { // something that might throw an exception } catch (Exception ex) { // Log contents of ex here throw;
3
by: barker7 | last post by:
I am calling an unmanaged C++ method from C#. When an exception occurs in the C++ code, it gets caught in our C# code. CSharpMethod() { try { NativeCPPMethod(); } catch (Exception e)
5
by: Mr. SweatyFinger | last post by:
WHY CAN'T THE CLOWN -HOLES WHO WROTE ASP.NET PROVIDE AN ERROR LINE NUMBER??? HONEST TO SH@THOLE PETE Server Error in '/New Folder (7)' Application....
2
by: pavel.orehov | last post by:
Hi, I am using Environment.StackTrace to print the stack trace to the log when I have any exceptions in my application. When I work in development environment I see the line numbers in the...
3
by: Dave Anson | last post by:
I have a custom exception and I want to write the information to the event log, including the Stack Trace. I can create the message and write to the event log no problem, but the Stack Trace is...
3
by: Sendil kumar | last post by:
Hi All, Problem Stetement:I have a problem in getting stack trace when I ues std::exception. In my code, I allocate virtual memory for certain kind of processing and will throw the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.