Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is explained thoroughly in the VB6 manual under <a href="http://msdn.microsoft.com/en-us/library/aa241677(VS.60).aspx" rel="nofollow noreferrer">Error Handling Hierarchy</a>. <code>On Error Goto 0</code> disables the error handler in the <strong>current</strong> procedure, not in the procedures that called it. </p> <blockquote> <p>If an error occurs in a procedure and this procedure doesn't have an enabled error handler, Visual Basic searches backward through the pending procedures in the calls list — and executes the first enabled error handler it finds. If it doesn't encounter an enabled error handler anywhere in the calls list, it presents a default unexpected error message and halts execution.</p> </blockquote> <p>As others have said, you can go to <strong>Tools-Options-General</strong> tab and choose <strong>Break on all errors</strong>. That effectively disables all your On Error statements - the IDE will break immediately on every error.</p> <p>That can be irritating if your VB6 code throws errors as part of normal operation. For instance when you check whether a file exists, or when the user presses cancel in a common dialogue. You don't want the IDE to break every time on those lines. But you might have boilerplate error handlers in all your event handling procedures, to stop the program crashing out on unexpected errors. But they are a nuisance when you're debugging problems because the IDE doesn't break on the line with the error. One trick is to switch off those error handlers when running in the IDE, but keep them in the built executable. You do it like this. </p> <p>Drop these functions into a module. </p> <pre><code>Public Function InIDE() As Boolean Debug.Assert Not TestIDE(InIDE) End Function Private Function TestIDE(Test As Boolean) As Boolean Test = True End Function </code></pre> <p>Then you can write your error handlers like this.</p> <pre><code>Private Sub Form_Load() If Not InIDE() Then On Error Goto PreventCrashes &lt;lots of code&gt; Exit Sub PreventCrashes: &lt;report the error&gt; End Sub </code></pre> <p>Pinched from <a href="http://objectmix.com/basic-visual/166962-how-tell-if-my-vb6-program-running-under-debugger.html" rel="nofollow noreferrer">here</a>. Another tip - use the free add-in <a href="http://www.mztools.com/v3/mztools3.aspx" rel="nofollow noreferrer">MZTools</a> to automatically add these boilerplate error handlers. For production-quality code, you could go further and put an error handler in every routine to create a <a href="https://stackoverflow.com/questions/116289/what-is-the-better-way-to-handle-errors-in-vb6/116498#116498">ghetto stack trace</a>. You might also log the errors immediately in every error handler.</p> <p>EDIT: Ant has correctly pointed out that <code>On Error Goto -1</code> is a <a href="http://msdn.microsoft.com/en-us/library/5hsw66as(VS.80).aspx" rel="nofollow noreferrer">VB.Net statement</a> and isn't valid in VB6.</p> <p>EDIT: Arvo and OneNerd have written answers with some interesting discussion of emulating Finally teardown blocks in VB6 error handling. The discussion in <a href="https://stackoverflow.com/questions/116289/what-is-the-better-way-to-handle-errors-in-vb6">this question</a> is also worth a look.</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