Link to home
Start Free TrialLog in
Avatar of BigBoss
BigBoss

asked on

Retrieving the name of procedure currently executing...

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.
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

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
Avatar of willisp
willisp

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

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.
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.
Avatar of BigBoss

ASKER

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.
Avatar of BigBoss

ASKER

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.
let a mod put it in the PAQ then
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial