Closing an application when catching a fatal error

  • Thread starter Thread starter Silby
  • Start date Start date
S

Silby

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.Exit(), 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 :)
 
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
 
Ahh, excellent.
Thanks for the tip !

Ken Tucker said:
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
 
Back
Top