Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need error handlers, using <code>On Error Goto</code>, so that you can execute your own code when an error occurs. (BTW in VB6 they are called <em>errors</em> not <em>exceptions</em>.) The free tool <a href="http://www.mztools.com/v3/mztools3.aspx" rel="nofollow noreferrer">MZTools</a> is excellent - it can automatically insert the <code>On Error Goto</code> and an error handler which includes the name of the current routine. </p> <p>You also need a general routine that logs error details to a file, a little bit like this below. Health warning - I've just typed this straight in without testing it (<a href="http://codebetter.com/blogs/brendan.tompkins/archive/2005/02/27/56126.aspx" rel="nofollow noreferrer">air code</a>). </p> <pre><code>Sub MySub() On Error Goto ErrHandler '... Do something ...' On Error Goto 0 Exit Sub ErrHandler: Call LogError("MySub", Err, Error$) ' passes name of current routine ' End Sub ' General routine for logging errors ' Sub LogError(ProcName$, ErrNum&amp;, ErrorMsg$) On Error Goto ErrHandler Dim nUnit As Integer nUnit = FreeFile ' This assumes write access to the directory containing the program ' ' You will need to choose another directory if this is not possible ' Open App.Path &amp; App.ExeName &amp; ".log" For Append As nUnit Print #nUnit, "Error in " &amp; ProcName Print #nUnit, " " &amp; ErrNum &amp; ", " &amp; ErrorMsg Print #nUnit, " " &amp; Format$(Now) Print #nUnit Close nUnit Exit Sub ErrHandler: 'Failed to write log for some reason.' 'Show MsgBox so error does not go unreported ' MsgBox "Error in " &amp; ProcName &amp; vbNewLine &amp; _ ErrNum &amp; ", " &amp; ErrorMsg End Sub </code></pre> <p>Bonus suggestion: <a href="https://stackoverflow.com/questions/1098863/runtime-error-stacktrace-or-location-in-vb6/1099804#1099804">roll your own stack trace</a>.<br> Bonus suggestion 2: switch off the error handlers in the IDE with something like this <code>If Not IsInIDE() Then On Error Goto Handler</code>, using the <code>IsInIDE</code> function from <a href="http://vbnet.mvps.org/index.html?code/helpers/isinide.htm" rel="nofollow noreferrer">here</a> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload