473,503 Members | 9,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 24483
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
2477
by: Andy Fish | last post by:
Hi, in my c# code I have something like this: try { ... } catch (Exception ex) { ... throw ex; }
3
5423
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
3662
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
4367
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
3702
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
1934
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
3453
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
7212
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
7690
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
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7095
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...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.