Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the Event, Function of Sub name for Error logging

Status
Not open for further replies.

MikeWare

Programmer
Sep 25, 2002
5
CA
Hi!
I'm currently tryin to write a generic "Error Handling code" so I can cut-and-paste it in every _Event, Sub and
Function in the VB project I'm working on. The idea is to log a few information on the context in which an error has occured.

AddError2DB Err.Number,Err.Description,"WhereItHappen",Time

What I need to complete the is the "WhereItHappen" part.
Because I don't want to customize every error handling call
...
AddError2DB Err.Number, Err.Description, "Form_Load", Time
...
AddError2DB Err.Number, Err.Description, "cmdA_Click", Time

Can somebody help me to get the name of the Event, Function or Sub when the programme run into it...

Thank a lot. ;o)
 
As far as I know, you could only get the name of the function from the stack, which is probably a bit beyond most VB programmers (myself inclueded!). Personally, I don't think that it's too big of a deal to copy/paste the name of the event-sub (Command1_Click) and have the AddError2DB sub separate the object from the event. Just double-click,ctrl+c,point,click,ctrl+v... takes like 3 seconds :) Hope this helps.

<aptain/\/64
 
Check out this reference:


For info on how to use the StackWalk API call to determine the call stack in a compiled EXE. It's pretty complicated though, and may be more trouble than it's worth to do this verses what you are doing.

The main fault with the method you describe, is that you will know what function or sub the error occured in, but you may not know what sub or function called the one that the error occured in, depending on your program's complexity. Going through the call stack eliminates this because it shows all of the proceedures that called the current one.

From what I understand, .NET has this built in. I'm not sure about this though.

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top