try catch - error handling

gazeranco

Well-known member
Joined
Feb 11, 2006
Messages
45
Location
Englandshire!
Programming Experience
Beginner
Hello all,

my new rss reader program is very buggy contantly throwing errors etc

Just wondering what is the best way of coding in my error handling, do i just work through and do it, or is there a way to make all my error handling be in a seperate file? :confused:

Some examples of error catching would be greatly appreciated :)
 
Well, the book i oncr read said that any code that could potentially cause an exception should be enclosed in the class the code executed in. Though i'm wouldn't dare to say that this is the definitive way to do it. Error handling in vb.net is fairly straight forward. If you've got a block of code that could error then enclose it in a Try/End Try Block like so.....


VB.NET:
Dim Con as new oledbconnection
Con.connectionstring = Some string
 
Try
Con.open
catch ex as oledbexception
messagebox.show(ex.message)
finally 
con.close
end try

Just an example. As the code above shows you can 'Catch' a specific type of exception and deal with it in a certain way or you can use a generic exception....

VB.NET:
catch ex as exception.
Note that throwing exceptions is an expensive process and should be avoided at all costs. To quote from Tech Gnome..

Use Offensive programming not defensive programming.
 
I get what your saying, Rather then catch an exception stop it happening in the first place ;) I plan on doing that just as soon as all the basics are working :)

Thanks Vis!
 
Back
Top