Bob,
In addition to the other's comments.
Normally I only include Try/Catch blocks in methods, when I know there is
something specific that I need to do with the exception. For example the
method may cause an UnauthorizedAccessException, and the
UnauthorizedAccessException is O.K. and I should just continue processing.
More likely is I will have Try/Finally blocks in methods to clean up
resources. In C# the using statement makes this easier. For example if I
opened a connection to a database, I would use a Try/Finally to ensure the
connection is closed when the method exits.
For most exceptions I simply let the global exception handler deal with the
exception, which normally includes logging the exception, and possible email
notification.
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/is...6/default.aspx
Unfortunately the article is not on-line yet.
Hope this helps
Jay
"Bob Rock" <no***************************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello,
this is something I've been asking myself for sometime ... and now I'd
like to clarify this point.
When should the try block start in a method??? What I mean is, does having
all the code instead of a smaller set of it inside a try clause add any
overhead??? 1What I'd like to understand is if, to be completely sure that
no unhandles exception will get to the user, I can place all the code
inside a try block
and if this practice adds unnecessary overhead (memory usage, more cpu
cycles, etc.) or if having a smaller set of instructions instead of all
the code under a try has the EXACT SAME effect on resources (overhead).
Bob Rock