I am developing a simple error message class and would like the be able to
generate as part of the message the curent class/module/form and function or
sub that the error was generated in without having to hardcode this info to
be passed to the error message class. I can get the stack trace using
system.environm ent.stacktrace - but this is too much info. I just want to
display the function/sub name where the error was generated and the parent
name of that sub/function
Any ideas?
Thanks, Brad
Thanks, Brad 7 3049
"Brad Pears" <br***@truenort hloghomes.comwr ote in
news:Og******** ******@TK2MSFTN GP04.phx.gbl:
I am developing a simple error message class and would like the be
able to generate as part of the message the curent class/module/form
and function or sub that the error was generated in without having to
hardcode this info to be passed to the error message class. I can get
the stack trace using system.environm ent.stacktrace - but this is too
much info. I just want to display the function/sub name where the
error was generated and the parent name of that sub/function
System.Reflecti on.MethodBase.G etCurrentMethod .Name will return the current
procedure name.
Does it also return who called that procedure at all?
Brad
"Spam Catcher" <sp**********@r ogers.comwrote in message
news:Xn******** *************** ***********@127 .0.0.1...
"Brad Pears" <br***@truenort hloghomes.comwr ote in
news:Og******** ******@TK2MSFTN GP04.phx.gbl:
>I am developing a simple error message class and would like the be able to generate as part of the message the curent class/module/form and function or sub that the error was generated in without having to hardcode this info to be passed to the error message class. I can get the stack trace using system.environm ent.stacktrace - but this is too much info. I just want to display the function/sub name where the error was generated and the parent name of that sub/function
System.Reflecti on.MethodBase.G etCurrentMethod .Name will return the current
procedure name.
Does it also return who called that procedure at all?
Try:
Dim sf As StackFrame = New StackFrame(iii, True)
Dim mb As Reflection.Meth odBase = sf.GetMethod
where StackFrame is defined in System.Diagnost ics, and iii is the call
ancestry (0 = current sub/function, 1 = caller, 2 = caller's caller, etc).
Some useful display strings are:
mb.DeclaringTyp e().Name()
mb.Name
In a debug build, additional useful display strings are:
sf.GetFileName
CStr(sf.GetFile LineNumber)
You could also use System.Diagnost ics.StackTrace. It surprised me though in
the following code, the release mode version apparently optimized out
MethodOne and went directly to MethodTwo. This oddity was in Orcas, so I'd
be interested if it is not optimized out in VS 2005.
class Program
{
private static void MethodOne()
{
MethodTwo();
}
private static void MethodTwo()
{
System.Diagnost ics.StackTrace st = new
System.Diagnost ics.StackTrace( );
Console.Out.Wri teLine(st.ToStr ing());
System.Threadin g.Thread.Sleep( 5000);
}
static void Main(string[] args)
{
MethodOne();
}
}
"AMercer" wrote:
Does it also return who called that procedure at all?
Try:
Dim sf As StackFrame = New StackFrame(iii, True)
Dim mb As Reflection.Meth odBase = sf.GetMethod
where StackFrame is defined in System.Diagnost ics, and iii is the call
ancestry (0 = current sub/function, 1 = caller, 2 = caller's caller, etc).
Some useful display strings are:
mb.DeclaringTyp e().Name()
mb.Name
In a debug build, additional useful display strings are:
sf.GetFileName
CStr(sf.GetFile LineNumber)
Oops! Sorry about the incorrect language, but the VB should be similar!
"ModelBuild er" wrote:
You could also use System.Diagnost ics.StackTrace. It surprised me though in
the following code, the release mode version apparently optimized out
MethodOne and went directly to MethodTwo. This oddity was in Orcas, so I'd
be interested if it is not optimized out in VS 2005.
class Program
{
private static void MethodOne()
{
MethodTwo();
}
private static void MethodTwo()
{
System.Diagnost ics.StackTrace st = new
System.Diagnost ics.StackTrace( );
Console.Out.Wri teLine(st.ToStr ing());
System.Threadin g.Thread.Sleep( 5000);
}
static void Main(string[] args)
{
MethodOne();
}
}
"AMercer" wrote:
Does it also return who called that procedure at all?
Try:
Dim sf As StackFrame = New StackFrame(iii, True)
Dim mb As Reflection.Meth odBase = sf.GetMethod
where StackFrame is defined in System.Diagnost ics, and iii is the call
ancestry (0 = current sub/function, 1 = caller, 2 = caller's caller, etc).
Some useful display strings are:
mb.DeclaringTyp e().Name()
mb.Name
In a debug build, additional useful display strings are:
sf.GetFileName
CStr(sf.GetFile LineNumber)
Brad Pears wrote:
I am developing a simple error message class and would like the be able to
generate as part of the message the curent class/module/form and function or
sub that the error was generated in without having to hardcode this info to
be passed to the error message class.
System.Reflecti on.MethodBase.G etCurrentMethod ().Name
gets you the name of the currently executing method, but you have to
code it into every method. Tedious.
I can get the stack trace using system.environm ent.stacktrace
- but this is too much info.
You /can/ get the StackTrace and pull it to pieces to extract the bit(s)
you're after. You might add this to the constructor (Sub New) of your
"error message class":
Dim sf As System.Diagnost ics.StackFrame _
= New System.Diagnost ics.StackFrame( 1, False)
Dim method As System.Reflecti on.MethodBase _
= sf.GetMethod()
? method.Reflecte dType.FullName
? method.Name
I just want to display the function/sub name where the error was generated
and the parent name of that sub/function
IMHO, if you're using this to track down errors, then you /need/ the
/entire/ stack trace (and more). The logging class I use gets laced
into each and every method and is used to record the entry and exit
points of those methods, complete with arguments and return values.
Without /all/ of this, it's .. rather difficult, shall we say .. to get
to the bottom of what's going wrong.
HTH,
Phill W.
Any chance of getting a copy of that logging class you use and some
instructions on it's implementation and use? Sounds like something I might
want to use... :-)
Thanks, Brad
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
news:f7******** **@south.jnrs.j a.net...
Brad Pears wrote:
>I am developing a simple error message class and would like the be able to generate as part of the message the curent class/module/form and function or sub that the error was generated in without having to hardcode this info to be passed to the error message class.
System.Reflecti on.MethodBase.G etCurrentMethod ().Name
gets you the name of the currently executing method, but you have to code
it into every method. Tedious.
>I can get the stack trace using system.environm ent.stacktrace - but this is too much info.
You /can/ get the StackTrace and pull it to pieces to extract the bit(s)
you're after. You might add this to the constructor (Sub New) of your
"error message class":
Dim sf As System.Diagnost ics.StackFrame _
= New System.Diagnost ics.StackFrame( 1, False)
Dim method As System.Reflecti on.MethodBase _
= sf.GetMethod()
? method.Reflecte dType.FullName
? method.Name
>I just want to display the function/sub name where the error was generated and the parent name of that sub/function
IMHO, if you're using this to track down errors, then you /need/ the
/entire/ stack trace (and more). The logging class I use gets laced into
each and every method and is used to record the entry and exit points of
those methods, complete with arguments and return values. Without /all/ of
this, it's .. rather difficult, shall we say .. to get to the bottom of
what's going wrong.
HTH,
Phill W.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peter Åstrand |
last post by:
There's a new PEP available:
PEP 324: popen5 - New POSIX process module
A copy is included below. Comments are appreciated.
----
PEP: 324
Title: popen5 - New POSIX process module
|
by: Anonymous |
last post by:
I have a mixed-language pgm (Fortran and C++) which needs to pass a few
hundred values from C++ to Fortran. One way to do this is to have a
Fortran module and a C++ structure (or class) with an identical data
layout. I have used this idea with no problem, but it necessitates
making changes very carefully to the Fortran module and the C++
structure to keep them "in sync".
I am looking for a program which translates source files between...
|
by: Larry Bird |
last post by:
I've created a AlertDataClass below within the class I have tables and column that I've create. In the AlertDataAccess class I'm trying to insert data into my tables. AlertDataAccess is a Module that is trying to insert data into the tables. Within the AlertDataClass is subroutine that init and creates ColumnNames. In invoke the AddDataColumnNames() sub to create the column headers.
Why can't I see the column names in my module that I'm...
|
by: Larry Bird |
last post by:
I've created a AlertDataClass below within the class I have tables and column that I've create. In the AlertDataAccess class I'm trying to insert data into my tables. AlertDataAccess is a Module that is trying to insert data into the tables. Within the AlertDataClass is subroutine that init and creates ColumnNames. In invoke the AddDataColumnNames() sub to create the column headers.
Why can't I see the column names in my module that I'm...
|
by: craig.overton |
last post by:
All,
I am currently developing an FTP class in VB.NET. It's kid tested,
mother approved when trying to access an FTP Server on a Windows box
meaning I can connect, run commands, upload and download a file no
problem. My issues come when I try to use the same class with the same
commands to access an FTP server on a UNIX box. I can connect and login
just fine, but after that all my commands come back "500 'PWD': command
not understood."....
| |
by: Cottonwood |
last post by:
I want to call a C module from a Fortran program. Whatever I tried -
the linker could not find the C module. I know about the leading
underscore and switched even that off. I abstracted everything
possible. When I replace the C module by a Fortran subroutine linking
works. Here the Fortran subroutine that replaced the C module for
testing:
subroutine qqcprint
return
end
|
by: Bonzol |
last post by:
vb.net
Hey there, could someone just tell me what the differnce is between
classes and modules and when each one would be used compared to the
other?
Any help would be great
Thanx in advance
|
by: Donald Westfield |
last post by:
I have my own module, called mystuff.py, which is to be imported for an
app.
The number of classes in the module will vary, so I need a subroutine that
will instantiate all of them as objects, and assign a variable to each,
regardless of what names the classes are.
Then I need to be able to delete these objects from memory completely at
times.
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Uploading files from a local computer to a remote web server has many useful purposes, the most obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
| |