473,408 Members | 2,832 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,408 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 2874
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.