|
-
Sep 17th, 2003, 02:55 AM
#1
Error information [RESOLVED]
When an error occurs in my app, one of the things the error handler does is append some information to a log file such as date, time, error number and description.
I'd like to add to that the name of the procedure where the error took place. Is it possible to retrieve this information somehow, I mean without having to use a variable to tag each and every subroutine in the app?
Next I'd like to get the list of all the calling procedure's names and -this sounds even more difficult- the number of the line were the error was triggered. Any ideas?
Last edited by krtxmrtz; Sep 18th, 2003 at 12:29 PM.
-
Sep 17th, 2003, 04:21 AM
#2
Addicted Member
Here is some code I use in my app for error handling which writes the error to a log file:
VB Code:
On Error GoTo PROC_ERR
[COLOR=green]code goes here[/COLOR]
PROC_EXIT:
Exit Sub
PROC_ERR:
ErrorMsg Err.Number, Err.Description & ":" & CStr(VBA.Erl), "Save", TypeName(Me), _
Err.Source, SAVE_ERR
Resume PROC_EXIT
ErrorMsg is a global functon. The parameters passed to it are:
Err.Number - vb error ID number
Err.Description - vb error description
VBA.Erl - this is a undocumented function and will not show up in intellisense. This returns the line number where the error occurred, assuming ofcourse that you have line numbers in your code, otherwise it returns 0.
"Save" - this is the procedure name
TypeName(Me) - this is the module name
Err.Source - Source of the error ie. the project name
SAVE_ERR - a constant for the message box title
The ErrorMsg function sorts all these parameters out in a string to be displayed to the user and written to the log file.
Fortunately, I use CodeSmart and have this set up in a template which makes things easy.
Cheers
Jack
Last edited by Jackalx25; Sep 17th, 2003 at 06:58 AM.
-
Sep 18th, 2003, 05:46 AM
#3
Originally posted by Jackalx25
VBA.Erl - this is a undocumented function and will not show up in intellisense. This returns the line number where the error occurred, assuming ofcourse that you have line numbers in your code, otherwise it returns 0.
...
Fortunately, I use CodeSmart and have this set up in a template which makes things easy.
Hi Jack, (pun not intended)
I being an amateur vb-er am not familiar with those terms. Just what is intellisense? How about CodeSmart? I'd really like to have line numbers in the code but how can you turn them on, if this can be done automatically?
Thanks for the help.
-
Sep 18th, 2003, 07:40 AM
#4
-= B u g S l a y e r =-
I'm sure you use it all the time (Intellisense that is )
MSDN
The Text editor now features Automatic Statement Completion, also known as IntelliSense. IntelliSense puts the MFC, Win32, and ATL libraries virtually at your fingertips, displaying class members, function prototypes, identifier declarations, and code comments at the mouse or cursor location where you are editing your code. Simple keystrokes insert code elements directly into the source code file you're working in. IntelliSense also completes recognized words for you, saving you from having to type lengthy class or member names repetitively.
There is no built in feature in vb that will generate the line numbers for you. To do that you need an addin for vb that can do this. CodeSmart is such an addin.
you can offcourse type them in as you go along though...
-
Sep 18th, 2003, 08:42 AM
#5
Addicted Member
peet is spot on in what he says...
Addins like Codesmart make doing the time consuming activities such as adding line numbers, formatting code etc etc. a snap.
If you want something that is free you can get MxTools. You can get it at: www.mxtools.com
I am sure it allows you put line numbers into your code but am not sure about it's flexibility in setting up error handling templates.
About using VBA.Erl, if you type "VBA." vb will list a number of functions however you will not fine "Erl" among them. This is what I mean by not showing up in intellisense.
Cheers
Jack
-
Sep 18th, 2003, 10:14 AM
#6
MZtools has it all. I use it, it's free, its great.
-
Sep 18th, 2003, 12:24 PM
#7
The thing is I installed MZTools very recently but haven't played enough with it yet so I wasn't aware it could do that too.
Thanks a lot guys!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|