473,385 Members | 1,814 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,385 software developers and data experts.

Stack trace

JP
I managed to get error checking does in my application. In using the
Exception object I can get all the information I need about the error like
the line # where the exception occurred. IS there a way I can have it also
return my the physical line of code at that line number in the StackTrace as
well?????????? This would be helpful because some errors occur just b/c the
user didn’t login, thus a needed Session variable was not on that page.

I want to distinguish between errors b/c the user didn’t login (thus
redirecting to the login page) and those errors where "real" problem may
exist.
--
JP
..NET Software Develper
Jul 28 '05 #1
7 4976
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(System.Threading.Thr ead.CurrentThread,
true);

for (int i = 0; i < trace.FrameCount; i++)
{
System.Diagnostics.Debug.WriteLine(trace.GetFrame( i).ToString());
}

HTH
Erick Sgarbi
I managed to get error checking does in my application. In using the
Exception object I can get all the information I need about the error
like the line # where the exception occurred. IS there a way I can
have it also return my the physical line of code at that line number
in the StackTrace as well?????????? This would be helpful because some
errors occur just b/c the user didn’t login, thus a needed Session
variable was not on that page.

I want to distinguish between errors b/c the user didn’t login (thus
redirecting to the login page) and those errors where "real" problem
may exist.

Jul 28 '05 #2
JP
Didnt work, at last not the way I would like it to :) I actually want to see
the specfic line of code at the line# that blew up. IE: if line #45 contained
Session["myName"].ToString(), then I would redirect to login page, if the
line contained something other then "Session", then I would know thait its
probably something I need to look into. Did I do something wrong:

You code return the stack trace of:

CODE: Application_Error at offset 147 in file:line:column
\\myDomain\testsites\myC#WebApp\site\global.asax.c s:52:4
Invoke at offset 0 in file:line:column <filename unknown>:0:0 RaiseOnError
at offset 158 in file:line:column <filename unknown>:0:0 RecordError at
offset 149 in file:line:column <filename unknown>:0:0 ResumeSteps at offset
100 in file:line:column <filename unknown>:0:0
System.Web.IHttpAsyncHandler.BeginProcessRequest at offset 227 in
file:line:column <filename unknown>:0:0 ProcessRequestInternal at offset 487
in file:line:column <filename unknown>:0:0 ProcessRequest at offset 176 in
file:line:column <filename unknown>:0:0 ProcessRequest at offset 101 in
file:line:column <filename unknown>:0:0

--
JP
..NET Software Develper
"er***@csharpbox.com" wrote:
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(System.Threading.Thr ead.CurrentThread,
true);

for (int i = 0; i < trace.FrameCount; i++)
{
System.Diagnostics.Debug.WriteLine(trace.GetFrame( i).ToString());
}

HTH
Erick Sgarbi
I managed to get error checking does in my application. In using the
Exception object I can get all the information I need about the error
like the line # where the exception occurred. IS there a way I can
have it also return my the physical line of code at that line number
in the StackTrace as well?????????? This would be helpful because some
errors occur just b/c the user didnÂ’t login, thus a needed Session
variable was not on that page.

I want to distinguish between errors b/c the user didnÂ’t login (thus
redirecting to the login page) and those errors where "real" problem
may exist.


Jul 28 '05 #3
JP
Oh, wait it just dawned on me. How can I get a line of code from a page when
what is being used is a compiled version of my code? At the point of runtime
my code is no longer lines of text. I bet I cant do this.

Oh well
--
JP
..NET Software Develper
"er***@csharpbox.com" wrote:
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(System.Threading.Thr ead.CurrentThread,
true);

for (int i = 0; i < trace.FrameCount; i++)
{
System.Diagnostics.Debug.WriteLine(trace.GetFrame( i).ToString());
}

HTH
Erick Sgarbi
I managed to get error checking does in my application. In using the
Exception object I can get all the information I need about the error
like the line # where the exception occurred. IS there a way I can
have it also return my the physical line of code at that line number
in the StackTrace as well?????????? This would be helpful because some
errors occur just b/c the user didnÂ’t login, thus a needed Session
variable was not on that page.

I want to distinguish between errors b/c the user didnÂ’t login (thus
redirecting to the login page) and those errors where "real" problem
may exist.


Jul 28 '05 #4
> Oh, wait it just dawned on me. How can I get a line of code from a page when
what is being used is a compiled version of my code? At the point of runtime
my code is no longer lines of text. I bet I cant do this.


I bet you can, and I wish I knew how to do it too. Part of the trick is
that you need availablility of your app's pdp file where the relevant info is
located. The other part of the trick is using
System.Diagnostics.SymbolStore, and I am left baffled by the documentation.
ildasm.exe, the il disassembler, knows how to do it. jit debuggers know how
to do it. Perhaps some learned soul will tell us both how to do it.

Jul 28 '05 #5
I am not sure how you want to be using this. I only use fine grained trace
under development and not production. What exacly are you trying to achieve?
If you are trying to instrument an application I strongly advise you to take
a look at enteprise library the http://msdn.microsoft.com/library/de...tml/entlib.asp
and the guidelines for exception management. if you are trying to write something
more complex (like a debugger) you should post in the CLR or Sdk newsgroup.

Furthermore, there is a way to get debugging information during production
by using System.Diagnostics.Process.EnterDebugMode and LeaveDebugMode however
it is a more complex issue to retrieve info using this approach.
HTH
Erick Sgarbi
Oh, wait it just dawned on me. How can I get a line of code from a
page when what is being used is a compiled version of my code? At the
point of runtime my code is no longer lines of text. I bet I cant do
this.

Oh well

"er***@csharpbox.com" wrote:
System.Diagnostics.StackTrace trace = new
System.Diagnostics.StackTrace(System.Threading.Thr ead.CurrentThread,
true);

for (int i = 0; i < trace.FrameCount; i++)
{
System.Diagnostics.Debug.WriteLine(trace.GetFrame( i).ToString());
}
HTH
Erick Sgarbi
I managed to get error checking does in my application. In using the
Exception object I can get all the information I need about the
error like the line # where the exception occurred. IS there a way I
can have it also return my the physical line of code at that line
number in the StackTrace as well?????????? This would be helpful
because some errors occur just b/c the user didn?t login, thus a
needed Session variable was not on that page.

I want to distinguish between errors b/c the user didn?t login (thus
redirecting to the login page) and those errors where "real" problem
may exist.

Jul 28 '05 #6
I think you are asking this of JP rather than me, but I'll answer anyway.
I am not sure how you want to be using this. I only use fine grained trace
under development and not production. What exacly are you trying to achieve?


My environment is several XP machines which will all have different debug
versions of projects, with pdb files and whatever else is needed. The
problem is that the end users are not experienced developers, and they won't
(can't?) learn about debuggers and the .net ide. So, when a problem (an
exception) happens, we want to report back lots of info to developers on the
same network without user intervention. The shop is 24/7, so a developer
will not necessarily be available when an exception occurs. I would like to
include some source code (as does JP) because the development environment is
fluid and line numbers go out of date quickly.

To summarize, the environment is entirely development/debug but with the end
users unable and unwilling to participate in the technical aspects. The site
is physically secure - we are not concerned about deploying pdb files.
Obfuscation is not in our game plan.

Now, we could deploy all the source code with each debug project. When an
exception occurs, with stacktrace we could get source file and source line
number and read the source file to find the line. But it seems to me that
that is what the pdb file is for. The problem is, I don't see how to do it.

Alternatively, we could launch into an industrial strength version-control
enterprise and keep book on what versions are deployed on what machines so
that line numbers are all we need to work on a problem. But deploying the
pdb file seems better in all ways. In the first place, it represents truth
about how the app was built. In the second place, if a developer is
available when an exception occurs, then jit to the rescue.

All of which leaves the open question: How do I do what ildasm does? FYI,
if the technology is with .net fw objects, I want to implement using the fw
objects. If the technology gets heavily into win apis, then we are
considering running ildasm to fetch source lines.

Jul 29 '05 #7
> My environment is several XP machines which will all have different debug
versions of projects, with pdb files and whatever else is needed.
The problem is that the end users are not experienced developers, and they won't (can't?) learn about debuggers and the .net ide.
Hold that thought for a second...
To summarize, the environment is entirely development/debug but with the end users unable and unwilling to participate in the technical aspects.
Right, can you please clarify "end users"? IMHO, "end users" are those whom
we ship the product... did you mean testers?
To summarize, the environment is entirely development/debug but with the end users unable and unwilling to participate in the technical aspects.
I will accept that you are refering to "end users" as testers... Testers
are supposed to be experienced on what they do but they dont need to know
about debuggers.

The site is physically secure - we are not concerned about deploying pdb files.
I would be, running software in debug mode slow down the app. As far as I
know it will disable optmizations.
Now, we could deploy all the source code with each debug project. When an exception occurs, with stacktrace we could get source file and source line number and read the source file to find the line. But it seems to me that that is what the pdb file is for. The problem is, I don't see how to do it. I am not familiar with the software development methodology (or life cycle)
you're using so I cant give you a honest opinion but i'll say this... if
you are worried about which line of code an exception was thrown your code
is not ready for QA tests. I never heard of anyone needing to consider shipping
code (which is not necessary anyway) for discovering bugs.

Review your SDLC...Make sure exceptions you are throwing have informative
info... use unit tests, they are your best friend for fixing and chasing
bugs...have some form of continuos integration (look at http://www.martinfowler.com/articles...tegration.html
and http://cruisecontrol.sourceforge.net/)...can not stress this enough,
try to review your testing/shipping iterations, have a look at http://msdn.microsoft.com/library/de...2/html/mtf.asp.


HTH
Erick Sgarbi
www.blog.csharpbox.com
I think you are asking this of JP rather than me, but I'll answer
anyway.
I am not sure how you want to be using this. I only use fine grained
trace under development and not production. What exacly are you
trying to achieve?

My environment is several XP machines which will all have different
debug versions of projects, with pdb files and whatever else is
needed. The problem is that the end users are not experienced
developers, and they won't (can't?) learn about debuggers and the .net
ide. So, when a problem (an exception) happens, we want to report
back lots of info to developers on the same network without user
intervention. The shop is 24/7, so a developer will not necessarily
be available when an exception occurs. I would like to include some
source code (as does JP) because the development environment is fluid
and line numbers go out of date quickly.

To summarize, the environment is entirely development/debug but with
the end users unable and unwilling to participate in the technical
aspects. The site is physically secure - we are not concerned about
deploying pdb files. Obfuscation is not in our game plan.

Now, we could deploy all the source code with each debug project.
When an exception occurs, with stacktrace we could get source file and
source line number and read the source file to find the line. But it
seems to me that that is what the pdb file is for. The problem is, I
don't see how to do it.

Alternatively, we could launch into an industrial strength
version-control enterprise and keep book on what versions are deployed
on what machines so that line numbers are all we need to work on a
problem. But deploying the pdb file seems better in all ways. In the
first place, it represents truth about how the app was built. In the
second place, if a developer is available when an exception occurs,
then jit to the rescue.

All of which leaves the open question: How do I do what ildasm does?
FYI, if the technology is with .net fw objects, I want to implement
using the fw objects. If the technology gets heavily into win apis,
then we are considering running ildasm to fetch source lines.

Jul 30 '05 #8

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...
1
by: Jason Coyne | last post by:
I am trying to use the StackTrace class to get my current stack trace for some logging. Everything is working fine, except when I am using threading (specifically WaitCallBack and...
3
by: Jeremy | last post by:
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...
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....
4
by: call_me_anything | last post by:
Here is a code to have a debug printf : #ifdef DEBUG #define DEBUG_printf(...) {printf(":",__FUNCTION__);printf(__VA_ARGS__);printf("\n");} #else #define DEBUG #endif int main () {
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.