Closing an application when catching a fatal error

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

    Closing an application when catching a fatal error

    Hi,

    I've a form.load event that initializes a cardreader, which is crucial to
    the operating of the program.
    Now if that throws an exception, the program needs to give a message and
    close down.
    I tried using Application.Exi t(), but that happily executes the rest of the
    code (initializing a browser component and adding some images to buttons).
    Does anyone have any idea on how to make the program *really* shutdown
    without running anything more ? Except maybe form.closing, that could come
    in handy too :)


  • Ken Tucker [MVP]

    #2
    Re: Closing an application when catching a fatal error

    Hi,

    Initialize your cardreader in a sub main(in module). If cardreader
    doesnt throw an exception show the Form. Of course make sub main your
    startup object.

    Public sub Main

    Try
    'Initialize CardReader Here
    Dim frm as new Form1

    Application.Run (frm)
    Catch ex as exception
    Messagebox.Show ("An Error has Occurred")
    end try
    end sub

    Ken
    ----------------------------
    "Silby" <Silby@nothanks .net> wrote in message
    news:ekkxb.4596 6$HT.1510456@ph obos.telenet-ops.be...[color=blue]
    > Hi,
    >
    > I've a form.load event that initializes a cardreader, which is crucial to
    > the operating of the program.
    > Now if that throws an exception, the program needs to give a message and
    > close down.
    > I tried using Application.Exi t(), but that happily executes the rest of[/color]
    the[color=blue]
    > code (initializing a browser component and adding some images to buttons).
    > Does anyone have any idea on how to make the program *really* shutdown
    > without running anything more ? Except maybe form.closing, that could come
    > in handy too :)
    >
    >[/color]


    Comment

    • Silby

      #3
      Re: Closing an application when catching a fatal error

      Ahh, excellent.
      Thanks for the tip !

      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
      news:ewovyZNtDH A.2392@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi,
      >
      > Initialize your cardreader in a sub main(in module). If[/color]
      cardreader[color=blue]
      > doesnt throw an exception show the Form. Of course make sub main your
      > startup object.
      >
      > Public sub Main
      >
      > Try
      > 'Initialize CardReader Here
      > Dim frm as new Form1
      >
      > Application.Run (frm)
      > Catch ex as exception
      > Messagebox.Show ("An Error has Occurred")
      > end try
      > end sub
      >
      > Ken
      > ----------------------------
      > "Silby" <Silby@nothanks .net> wrote in message
      > news:ekkxb.4596 6$HT.1510456@ph obos.telenet-ops.be...[color=green]
      > > Hi,
      > >
      > > I've a form.load event that initializes a cardreader, which is crucial[/color][/color]
      to[color=blue][color=green]
      > > the operating of the program.
      > > Now if that throws an exception, the program needs to give a message and
      > > close down.
      > > I tried using Application.Exi t(), but that happily executes the rest of[/color]
      > the[color=green]
      > > code (initializing a browser component and adding some images to[/color][/color]
      buttons).[color=blue][color=green]
      > > Does anyone have any idea on how to make the program *really* shutdown
      > > without running anything more ? Except maybe form.closing, that could[/color][/color]
      come[color=blue][color=green]
      > > in handy too :)
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...