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

Preserving run-time error messages

Status
Not open for further replies.

NeilFrank

Programmer
Mar 12, 2000
167
CA

Is there a way to save the details of a VB6 run-time error at run-time, ie to write to a pre-specified file:
[1] the error message,
[2] the location in the program, and
[3] the offending line of code?

after the error is detected and before the App crashes

Thanks gurus!
 
An error trap will give you the ERRNO and the ERRL (Error Number and Line number) From that, you can get a description as well.

Download MZTools, which lets you add auto code functions like this.

Code:
  On Error GoTo {PROCEDURE_NAME}_Error

	{PROCEDURE_BODY}

   On Error GoTo 0
   Exit {PROCEDURE_TYPE}

{PROCEDURE_NAME}_Error:

	MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure {PROCEDURE_NAME} of {MODULE_TYPE} {MODULE_NAME}"

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
If you're going to do this on an application-wide scale, you might consider putting your logging logic into one procedure and calling it from error-handling stubs in each of your application procs.
 
Is there, perchance, a VB6 Procedure Name property (see *** below) which I could send to the global error logging routine? This would save me a LOT of code-editing!

eg

Private Sub Foo
On Error GoTo CrashLog

{Procedure Body }

Exit Sub
CrashLog:
x = Procedure.Name '*****
Call CrashWrite(Err.Number, Err.Description, x)
End Sub


Public Sub CrashWrite(iE As Integer, sE As String, sR As String)
MsgBox "Error " & iE & " ( " & sE & " ) in Procedure " & sR
End Sub
 
Sadly, no, although not so sad in this case. Here, you can put the proc name verbatim in Err.source, which is actually easier than your proposed solution anyway:
Code:
Sub Foo()
On Error Goto ErrHandle
DoThis
DoThat
Exit Sub
ErrHandle:
   MyErrorHandler Err.number, "Foo", Err.Description
End Sub
 
Thanks, but it IS sad - and puzzling, as it would seem to be an obvious and useful feature - since I was hoping to avoid having to explicitly pass, as a String, the name of each of my procedures - there are almost 2,000 - to my CrashWrite routine.

In other words, I will have to add a unique line of code to each procedure, ie

Call CrashWrite(Err.Number, Err.Description, "Foo")

instead of adding the identical line to each procedure, ie

Call CrashWrite(Err.Number, Err.Description, Procedure.Name)
 
Error handling has always been rather simple-minded in VB, I'm afraid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top