Overuse of try catch?

  • Thread starter Thread starter STom
  • Start date Start date
William Ryan said:
Are you serious? I was actually ready to really defend my position until I
read the rest of your post.... I'll promise you, even the Linux crowd will
back me on this one.. I can't wait until your job moves to another country!

Sure, moron, given that "the Linux crowd" still primarily uses C,
and thus neither RAII nor the Rule of Three will apply to them.
However, you made the ludicrous claim that you are a "seasoned C++
programmer", when in fact you appear to be unfamiliar with idioms
that have been standard practice in C++ for nearly ten years. Are
you even aware that C and C++ are different languages at all?
 
Rob Teixeira said:
Feel free to search the various VB groups for Joe Foster and Matt Curland.
You know exactly what I'm talking about.

Put down the crack pipe and back away slowly. My complaints about
Matthew "Access to Source" Curland have primarily to do with his
rather fragile "solutions", such as his "lightweight COM objects",
not with the concept of value types with methods and destructors.
I've been wishing for Type_Initialize and Type_Terminate in Visual
Basic for quite some time.
 
STom,
In addition to Tom's article:

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.

Something like:

Public Sub Main()
AddHandler Application.ThreadException, AddressOf OnThreadException
Application.Run(New MainForm)
End Sub

Private Sub OnThreadException(sender As Object, _
ByVal e As System.Threading.ThreadExceptionEventArgs)
Try
' Log the exception & possible show user the info...
Catch ex As Exception
' Don't want to end the app here! ;-)
End Try
End Sub

Using one (or more) of the above global handlers allows your application to
log the exception in the handler and allows your app to continue processing,
saving your from adding Try/Catch in each of your Form's event handlers for
example.

Hope this helps
Jay


STom said:
Thanks Tom for pointing me to the article...and thanks to everyone else for
their thoughts/opinions...I did not intend to start a war though :-)

My thought behind try/catch is that if there is an exception, and the app is
going to halt anyway, how terribly important is it that it halts quickly?
For example, if the exception were thrown 8 levels deep and had to be
rethrown all the way back to the top, the app is going to probably appear to
hang for a short period of time before a message box or whatever displays
the error.

Thanks again.

STom
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetperftips.asp
 
Back
Top