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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Procedure / Method Name 2

Status
Not open for further replies.

jizviz

Programmer
Oct 13, 2002
26
0
0
US
I'm setting up an error log and would like to be able to get the current method/procedure name to send to my error logging routine. Any thoughts?

Thanks
 

Short answer - no, sorry.

But if you set your error handler in a module, you can pass a Form and get Form's name and active control where the error happened:
Code:
Public Sub MyErrorHandler(myForm As Form)

Debug.Print myForm.ActiveControl
Debug.Print myForm.Name

End Sub


Have fun.

---- Andy
 
Thanks, I thought I wasn't able to get that info.
 
>Short answer - no, sorry

Which is correct. There is no way of an error handler knowing the proceedure name with the error unless you pass the name back.

If the proceedure already has an error handler, then when calling your error logging routine you can pass the name of the proceedure using the "Source" argument.

If it doesn't have an error handler, then the error handling routine in the calling proceedure, or somewhere up the stack, should kick in.

In order to pass back the needed information though, you would need to use the err.raise method. A simple example of this which gets added to every proceedure needing this would be like:

Sub MyProceedure1()
On Error goto MyErrorHandler
.
.
.
MyErrorHandler:
If err.number <>0 then
Err.Raise err.number, "MyProceedure1", err.description
End if
End Sub

This example would not change your current error handling logic at all, except for the fact that the added code "steps in between" and adds information, and then allows the error to carry on as before.
In doing it this way, the error is explicitly passed back to the calling proceedure, with the added, or if so desired, changed information, instead of VB moving up the stack until it finds an error handler, or not (crashes).
 
Thanks for the info. I guess I have to pass the proc name manually
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top