Jesper,
In addition to the other comments.
What are you planning on doing with the Exception?
I find it better to not catch exceptions unless there is something specific
I am going to do with it. For example catching the FileNotFound exception to
allow the user to try a different file. While logging the exception is
normally not specific enough for me to catch inline.
Rather I simply let exceptions float up to the Global Exception Handlers,
where I do any exception logging. However! I will use Try/Finally & the
Using statement to clean up any resources (call the Dispose methods).
In other words I favor Try/Finally (good) over Try/Catch (not as good). I
use Try/Catch where I have something specific to do with that specific
exception.
See the MSDN Mag article below for details.
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.
Hope this helps
Jay
"Jesper Ordrup Christensen"