VB6 - How to catch exception or error during runtime

error-handling, vb6

Solution

You've probably done something to clear the `Err` object before writing to the log file. This is very, very easy to do. What you'll want to do is as soon as you detect an error has occurred, grab the error message before doing anything else. Then pass the error message to whatever logging routine you're using. E.g.:

Dim sMsg As String

On Error Goto ErrHandler

' ...code here...

Exit Function

ErrHandler:
sMsg = "Error #" & Err.Number & ": '" & Err.Description & "' from '" & Err.Source & "'"
GoLogTheError sMsg

Problem

I developed an application in VB6. In client's environment it raises runtime errors which I can't reproduce under debugger. Is there any way to get the stacktrace or location of error? I created log file and I used Err.Description,Err.Source but it gives blank values. Please help me. ``` my method(...... On Error GoTo Error_Handler ......... Error_Handler : writeToLogFile(Err.Source,Err.Description) ```

Original source