Error Handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Turner

    #1

    Error Handling

    Morning all,
    Below is a piece of code to deal with a deliberate error.
    Can someboby explain why, in run mode, 'errhandler'
    is not reached, but the error is caught by the standard error
    handler, whereas in the compiled EXE, it runs as expected?
    This makes writing error handling routines difficult, since
    I have to compile the app to find out if the errhandler works OK!

    TIA
    Geoff Turner

    ....code follows...

    Private Sub cmdTest_Click()

    On Error GoTo errhandler

    Print 2 / 0

    Exit Sub

    errhandler:
    MsgBox "Oh dear, ERROR"

    Exit Sub

    End Sub


  • Visual Boodu .NET

    #2
    Re: Error Handling

    Works for me.. Code looks fine also. If you press F8 and step through the
    code, what happens? What version of VB do you have? Do you have the latest
    service pack?

    Maybe someone else can give you ideas.

    Geoff Turner wrote:[color=blue]
    > Morning all,
    > Below is a piece of code to deal with a deliberate error.
    > Can someboby explain why, in run mode, 'errhandler'
    > is not reached, but the error is caught by the standard error
    > handler, whereas in the compiled EXE, it runs as expected?
    > This makes writing error handling routines difficult, since
    > I have to compile the app to find out if the errhandler works OK!
    >
    > TIA
    > Geoff Turner
    >
    > ...code follows...
    >
    > Private Sub cmdTest_Click()
    >
    > On Error GoTo errhandler
    >
    > Print 2 / 0
    >
    > Exit Sub
    >
    > errhandler:
    > MsgBox "Oh dear, ERROR"
    >
    > Exit Sub
    >
    > End Sub[/color]


    Comment

    • Geoff Turner

      #3
      Re: Error Handling

      In response to your response:
      Bombs out at the line ' Print 2 / 0 '
      VB 6
      Windows NT and Windows 98; behaviour identical on both platforms.

      "Visual Boodu .NET" <sn@il.mail> wrote in message
      news:dZQcc.2161 $8P2.577@news-server.bigpond. net.au...[color=blue]
      > Works for me.. Code looks fine also. If you press F8 and step through[/color]
      the[color=blue]
      > code, what happens? What version of VB do you have? Do you have the[/color]
      latest[color=blue]
      > service pack?
      >
      > Maybe someone else can give you ideas.
      >
      > Geoff Turner wrote:[color=green]
      > > Morning all,
      > > Below is a piece of code to deal with a deliberate error.
      > > Can someboby explain why, in run mode, 'errhandler'
      > > is not reached, but the error is caught by the standard error
      > > handler, whereas in the compiled EXE, it runs as expected?
      > > This makes writing error handling routines difficult, since
      > > I have to compile the app to find out if the errhandler works OK!
      > >
      > > TIA
      > > Geoff Turner
      > >
      > > ...code follows...
      > >
      > > Private Sub cmdTest_Click()
      > >
      > > On Error GoTo errhandler
      > >
      > > Print 2 / 0
      > >
      > > Exit Sub
      > >
      > > errhandler:
      > > MsgBox "Oh dear, ERROR"
      > >
      > > Exit Sub
      > >
      > > End Sub[/color]
      >
      >[/color]


      Comment

      • Geoff Turner

        #4
        Re: Error Handling Solved!

        Problem solved.
        Under "Tools/Options/General/ErrorTrapping" I have the option to select
        "Break on all Errors" and "Break on Unhandled Errors"
        Changing to the latter solved the problem.

        Thanks all.
        Geoff.

        "Visual Boodu .NET" <sn@il.mail> wrote in message
        news:dZQcc.2161 $8P2.577@news-server.bigpond. net.au...[color=blue]
        > Works for me.. Code looks fine also. If you press F8 and step through[/color]
        the[color=blue]
        > code, what happens? What version of VB do you have? Do you have the[/color]
        latest[color=blue]
        > service pack?
        >
        > Maybe someone else can give you ideas.
        >
        > Geoff Turner wrote:[color=green]
        > > Morning all,
        > > Below is a piece of code to deal with a deliberate error.
        > > Can someboby explain why, in run mode, 'errhandler'
        > > is not reached, but the error is caught by the standard error
        > > handler, whereas in the compiled EXE, it runs as expected?
        > > This makes writing error handling routines difficult, since
        > > I have to compile the app to find out if the errhandler works OK!
        > >
        > > TIA
        > > Geoff Turner
        > >
        > > ...code follows...
        > >
        > > Private Sub cmdTest_Click()
        > >
        > > On Error GoTo errhandler
        > >
        > > Print 2 / 0
        > >
        > > Exit Sub
        > >
        > > errhandler:
        > > MsgBox "Oh dear, ERROR"
        > >
        > > Exit Sub
        > >
        > > End Sub[/color]
        >
        >[/color]


        Comment

        • Bob Butler

          #5
          Re: Error Handling

          "Geoff Turner" <g.s.turner@rl. ac.uk> wrote in message news:<c50id6$p3 0@newton.cc.rl. ac.uk>...[color=blue]
          > Morning all,
          > Below is a piece of code to deal with a deliberate error.
          > Can someboby explain why, in run mode, 'errhandler'
          > is not reached, but the error is caught by the standard error
          > handler, whereas in the compiled EXE, it runs as expected?
          > This makes writing error handling routines difficult, since
          > I have to compile the app to find out if the errhandler works OK![/color]

          right-click on the code window, select Toggle and make sure it is set
          to "Break On Unhandled Errors"

          Comment

          Working...