Exception Handling Approach ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am developing a new project in which we should have a good Exception
Handling. Ive seen there is a Exception Handling App Block in Enterprise
Library, also I could use the Try-Catch structure itself...
What would be the best Approach ?
 
You will be using both. Some exceptions you expect (and handle) other ones
you don't in which case they should fall to your unhandled exception
handler. Just be explicit as possible in your try catches ..

ex:

BAD

try {
File.Open ( ... )
}
catch(Exception Ex) {
MessageBox.Show("Could not open file " + Filename);
}

GOOD
try {
File.Open ( ... )
}
catch(FileNotFoundException Ex) {
MessageBox.Show("File not found " + Filename);
}

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
 
Greg,
the example u posted does not use EntLIbrary, right?
I need to understand in which cases I would use EntLibrary
ExceptionHandling...
 
That example for another exception would fall out to the default exception
handler ...

The entlib is often used with a default exception handler ..

Aside from that I would recommend a read through one of the many articles
available such as http://www.devx.com/dotnet/Article/31463

Cheers,

Greg
 
Back
Top