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

stack trace and stack frame

Hi all i posted this question yesterday. no answers yet.
please do reply if you have any ideas. thanks a lot.
Subject: stack frame stack trace
can the information from the stack be obtained only when
exceptions are thrown? kindly reply.
..
Nov 15 '05 #1
1 2868
Below is a simplified version of what I use in my tracing and error
handling.
It is used to build a message that includes information of both the stack
frame and
a message string/ID/severity

So, to answer your question, you can get information of the stack at any
time (and not only in case of exception handling)

If you want the information to be available in Release mode, you have to go
under
project property -> configuration property -> build (Release) and set
Generate Debug information to True.
José
//--------------------------------------------------------------------------
-------
/// <summary>
/// Simplified method used to build msg to be traced to local File.
/// </summary>
/// <param name="Msg">msg to be traced</param>
/// <param name="MsgStatus">Current StatusID of the message</param>
/// <param name="SeverLevel">Severity level</param>
/// <param name="stackFrameLevel">Index to consider in the stack frame to
retrieve information
/// (such as FileName, Method name and line#)</param>
/// <returns>original msg with extra information (dateTime,...)</returns>
protected string BuildMsg( string Msg,
int MsgID,
Severity.Level SeverLevel,
short stackFrameLevel)
{
try
{
// Convert severity to 1 char
string strCurrSeverity = Severity.ToShortString(SeverLevel);

// Get stack information (FileName, Method, Line#)
StackFrame stFrame = new StackFrame(stackFrameLevel, true);
string strFileName;
if ( stFrame.GetFileName() != null)
strFileName =
stFrame.GetFileName().Substring(stFrame.GetFileNam e().LastIndexOf(@"\")+1);
else
strFileName = "Unknown???";
string strFullInfo = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.ff",
null) +
" [" + gprocessInfo.MainModule.ModuleName + " - " +
strFileName + " - " + stFrame.GetMethod().Name +
"() - Line:" + (stFrame.GetFileLineNumber()).ToString() + "] " +
Environment.NewLine +
" [" + strCurrSeverity + ":" + MsgID.ToString("D5") + "] " +
Msg + Environment.NewLine;

return strFullInfo;
}
catch (Exception ex)
{
return "Unable to build msg for logger. Err: " + ex.ToString() +
". Make sure the .PDB file has been copied in the Binary directory!";
}
}

<an*******@discussions.microsoft.com> wrote in message
news:4c****************************@phx.gbl...
Hi all i posted this question yesterday. no answers yet.
please do reply if you have any ideas. thanks a lot.
Subject: stack frame stack trace
can the information from the stack be obtained only when
exceptions are thrown? kindly reply.
.

Nov 15 '05 #2

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; }
4
by: kevin.hall | last post by:
Is there a way with Linux x86 to report a way the current stack trace for a thread during runtime without a debugger? (I couldn't find anything searching Google.) For Windows this is possible. ...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
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;
2
by: news.microsoft.com | last post by:
Hi all. If I wanted to write something so that, when an exception was thrown, and the stack unwound, the stack trace was captured with the values of the parameters (instead of just the parameter...
7
by: David T. Ashley | last post by:
Is there any portable method for identifying the caller of a function, its caller, and so on, at runtime, without using a debugger? Clearly, one can dissect the stack frame and trace it back. ...
0
by: laurent | last post by:
Hi, I need some help with cordbg. I try to do some search on google, but don't find any answer. I try to use MDBGEngine to analyse the trace stack frame of an appplication which have...
1
by: davidcollins001 | last post by:
Hi, I am trying to write a stack walking program to trace back along the stack for a process that the trace function is called from. I am doing it the cheating way, in that I have a ruby program...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.