views:

409

answers:

2

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)


 
+1  A: 

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
T.J. Crowder
I already did this. but some time Err.Description gives me blank value.
Royson
`Err.Description` can be blank (try this `Err.Raise 1234567` to see that happen), `Err.Number` should always have a value, though.
T.J. Crowder
+1  A: 

Do you definitely, positively have an Exit Function just above the Error_Handler:?

MarkJ
Oh, nice one, that's a classic mistake. Though you'd expect if he's walking through with a debugger...
T.J. Crowder
@T.J. Crowder Even so... No disrespect meant to Royson, because I know I've certainly overlooked obvious stuff before
MarkJ
Oh, absolutely. You and me both.
T.J. Crowder