VB6 - How to Catch an Exception or Runtime Error

I developed the application in VB6. In the client environment, it causes runtime errors that I cannot reproduce under the debugger. Is there a way to get the stack or location of the error? I created a log file and

I used Err.Description, Err.Source but it gives null values.

Please help me.

my method(...... On Error GoTo Error_Handler ......... Error_Handler : writeToLogFile(Err.Source,Err.Description) 
+4
source share
4 answers

You probably did something to clear the Err object before writing to the log file. It is very, very easy to do. What you want to do is as soon as you find that an error has occurred, take the error message before doing anything else. Then report an error for any logging procedure you use. For instance:.

 Dim sMsg As String On Error Goto ErrHandler ' ...code here... Exit Function ErrHandler: sMsg = "Error #" & Err.Number & ": '" & Err.Description & "' from '" & Err.Source & "'" GoLogTheError sMsg 
+4
source

By the way, thanks for the answers your guys are helping me. I'm about a decade and a half before playing the VB6. I do not make windows unless forced;)

Anyway, when you do your error checking, say, among 3000 individual inserts of write requests, I learned a couple of tricks. Consider this block of code:

 '----- order number 1246------- On Error Goto EH1246: sSql="insert into SalesReceiptLine ( CustomerRefListID,TemplateRe..." oConnection.Execute sSQL sSql="SELECT TxnID FROM SalesReceiptLine WHERE RefNumber='1246'..." oRecordset.Open sSQL, oConnection sTxnId = oRecordset(0) oRecordset.Close sSql="INSERT INTO SalesReceiptLine (TxnId,SalesReceiptLineDesc,Sal..." oConnection.Execute sSQL EH1246: IF Err.Number<>0 THEN sMsg = sMsg & "Order # 1246; sTxnId = " & sTxnId & _ vbCrLf & Err.Number & ": " & Err.Description & vbCrLf sErrOrders = sErrOrders & "1246," End If On Error GoTo -1 '----- order number 1247------- On Error Goto EH1247: 

When you do not test Err.Number, you will receive 0: for each processed order. (maybe you don’t want it). Error On GoTo -1 resets the error so that it works again. Err seems to work only once.

I wrote a php script to build VB6 source code to run about 8000 odbc requests ...: P

+2
source

Do you definitely have Exit Function just above Error_Handler: :?

+1
source
  my method(...... On Error GoTo Error_Handler ........ Exit Sub Error_Handler : writeToLogFile(Err.Source,Err.Description) 

"Exit Sub" should be added before processing the function Error_Handler .....

0
source

All Articles