Retrieving the name of procedure currently executing...

BigBoss
BigBoss used Ask the Experts™
on
Hello,
I want to dump errors into an error log file.
I want to know the name of the procedure in which the error occurred so that I dump it to the file as well.
How can I get the name of this procedure that is currently executing (which has generated the error)?
I just want how to get the name of the procedure...not error handling code or how to dump to file....
Note: Every procedure do have an error handler.
Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Commented:
Hello BigBoss,

not automatically, or you should provide it in the error string manually

or use a a tool like documentor which documents all code and can insert error handlers with procname etc...

http://www.gridlinx.com/

HAGD:O)Bruintje

Commented:
Not sure if this is what you need, but here is an example:

Public Function Testit()

   On Error Resume Next

   Err.Raise -100, "Testit", "Testit Description"

End Function


Testit    'Call the function
if err.number <> 0 then
   msgbox "Error Source = " err.Source
   msgbox "Error Description = "err.Description
endif

VK

Commented:
Hello BigBoss !

I would consider learning how to enhance the vb-ide with addins. There is a documentation in the MSDN.

Other links:

http://kandkconsulting.tripod.com/VB/VBCode.htm
http://www.vb-faq.com/Articles/Fresle/addins.asp
....

regards

v.k.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

VK

Commented:
P.S.

Because you can only access your projects members and properties when you are in design mode, you have to write an vb-ide-addin which scans your code and inserts the code you want to be inserted. This means you have to rerun your addin and to recompile your project if for example the name of a procedure has changed.

Author

Commented:
Hi everybody,
Thank you all for your comments.
In fact, none of the suggestions is what I need.
I thought that there might be something in VB (or probably API) which can tell you the name of the procedure that is currently executing!
Once again, thank you all.
Why not declare a global variable, called procname, which you set to the name of each procedure in the first line of that procedure?  Then, at any point, you can refer to that global variable to find out what procedure is currently running.

E.g.
Public ProcName As String

Sub DoSomethingClever()
  ProcName = "DoSomethingClever"
  ' Plus the rest of the code to do something clever
End Sub

If you compile your application with the option to "Create Symbolic Debug Info", then yes, you can access the call stack from some form of general error handler routine you include in all of your functions.

Author

Commented:
Hi everybody,
I have requested my old *unanswered* questions to be deleted. So I just wanted to comment the questions.

Regarding this one, I think that the suggestions did not answer my question.

Thanks to everyone.
Top Expert 2006

Commented:
let a mod put it in the PAQ then
Commented:
PAQ'd and points refunded

modulo

Community Support Moderator
Experts Exchange

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial