Shane,
Do I try..catch and trap the error and if so what do I do with it?
IMHO that is the big question: "what do I do with it", if you do not have a
specific answer to that question, IMHO you should NOT be catching the
exception.
Ergo I find it better to not catch exceptions, rather I simply let them
float up to the Global Exception Handlers. That is not to say that I don't
use Try/Catch, I use Try/Catch where I have something specific to do with
that specific exception.
In other words Try/Finally is good, Try/Catch not so good.
See the MSDN Mag article below for details.
I normally use a global exception handler for logging and display to the
user. I use try/finally more then I use try/catch. I only use try/catch when
there is something specific that I need to do with the exception, otherwise
I let my global exception handlers handle the exception.
Depending on the type of application you are creating, .NET has three
different global exception handlers.
For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.
For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.
For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.
It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.
There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...
http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx
For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.
Note David has some excellent comments on argument validation to your class
libraries. Especially if those class libraries are going to be used outside
of your current solution.
Hope this helps
Jay