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

Return a procedure name?

Status
Not open for further replies.

vietnam97

Programmer
Sep 18, 2000
48
Is there a way to return a procedure name? I'm building an error handling routine, and want to return the procedure name where the run-time error occurred for ease of maintenance. [sig][/sig]
 
I actually try do this same thing in every program I write -- it makes debugging a snap.
Every module and function I write has a header and footer, like:

Private Const ModuleName = "MyModule"

Public Function MyFunction()

Const ProcName = "MyFunction"
On Error Goto ErrorHandle

'--------PROCEDURE CODE------------------


'--------ERROR HANDLERS------------------

ErrorHandle:
Dim ErrSource as String
ErrSource = Err.Source
'Filter out the App Name, so it won't be at the
'end of the string
If (ErrSource = App.Name) Then
ErrSource = ModuleName & "." & ProcName
Else
ErrSource = ModuleName & "." & "!" & ErrSource
End If

Err.Raise ErrSource, Err.Source, Err.Description

End Function

Whenever an error is raised, the error source is defaulted to the application name. So, if the error source is the app name, I know this is the beginning of the error, and I set the source to be the current module and procedure.
Since each procedure re-raises the error up the call stack to it's calling procedure, each procedure adds its module and procedure name to the front of the source, so by the time you get to the top of the call stack, you have a string that looks like

Module1.Proc1!Module2.Proc2!Module3.Proc3

So you know exactly which procedures were running when this error occurred.

This method is high maintenance -- you have a lot of copying and pasting to do (unless you get an add-in to do it for you), but it is the only way I've found to get this functionality.

If somebody else has an easier way to do this, I'd love to see it! :-Q

Steve [sig][/sig]
 
I use a similar piece of code that writes the errors to a table.
I was looking for something simple like function.name or procedure.name or module.name just like you have App.Name or Err.Source. It would make programming much easier if all things were consistent. :)
Often the question is do you use the way you do it now and spend hours with copy and paste or do you spend hours looking at sites like this for something that dosen't exist. The fun part is that when you look for things here you often find solutions to other little problems. I have found some good ones here.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top