Error handling in vb. net

S

Stefan Johansson

Hi all

I'am moving from Visual Foxpro and have a question
regarding "best practice" error handling in vb .net.
In VFP I have always used a "central" error handling
object in order to have a easy and reusable way of
handling all errors in a program.

The VB 6 coding examples I have seen there has always
been error handling code in each program module.

Is it possible in VB .net to use a central error handling
or is it not a "good way" of handling errors?

Stefan Johansson
 
S

strchild

Hi Stefan,

Try reading up on the:

Try
Catch
End Try

... method for error handling. I find it to be very easy to implement
and you can plop it pretty much anywhere you need to. I find this easier to
implement than trying to put everything into a centralized error handler
myself, but that's just personal preference I guess. Not really sure if
there is an advantage to one way versus another.

~Brian
 
C

Cor

Hi Stefan,

In addition to Brian, look also for "finally" .

Try
Just do what you want to do
Catch spEx as (a specialException)
DoSomething (by instance show a messagebox and do an action)
Catch Ex as Exception (you can real put those two ore more behind each
other)
(that catch every exception was not a special exception)
DoSomething (by instance show a messagebox and do an action)
Finally
(That is always done, it is very handy to close something )
End Try
 
H

Herfried K. Wagner [MVP]

* "Stefan Johansson said:
I'am moving from Visual Foxpro and have a question
regarding "best practice" error handling in vb .net.
In VFP I have always used a "central" error handling
object in order to have a easy and reusable way of
handling all errors in a program.

The VB 6 coding examples I have seen there has always
been error handling code in each program module.

Is it possible in VB .net to use a central error handling
or is it not a "good way" of handling errors?

In VB.NET, there are 2 error handling methods available: Structured
exception handling with 'Try...Catch' and unstructured error handling
with 'On Error GoTo...'. Have a look at the documentation for more
information on this topic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top