I came up with a rather novel approach to this, which we use in our apps. We
have a static error handler which identifies the type of Exception, and
depending upon the Exception type, extracts specific information from it for
loggin purposes. We have methods that work individually with various
Exception types, to extract the data from them and append to a
StringBuilder. The static Exception handler calls the appropriate method for
extracting the particular Exception type, and will call itself recursively
for any inner Exceptions. As a result, we get some good logging regarding
Exceptions. Now, this Exception handler can either rethrow the Exception, or
ignore it, in case a client app needs to do more with it. But the logging is
an invaluable diagnostic benefit.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eC**************@TK2MSFTNGP12.phx.gbl...
You can catch all exceptions by specifying catch(Exception...) however,
even though this is used extensively, it isn't reccommended practice. You
can expect certain sorts of exceptions, for example, if you're doing file
operations you may expect an io exception and wish to handle it in a
different way. In this case you can use catch blocks for all of the
exception types you expect to see and handle in a different way.
That being said, a generic catch of an exception is the lazy way out and
if you only have yourself to please then just go ahead...
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"___Newbie___" <d> wrote in message
news:%2***************@tk2msftngp13.phx.gbl... Hello,
Does every error encountered during try() block is handled by
catch(Exception e) ? Do I have to catch every aspect or every detail of
exception? e.g. catch (IOException io) catch (OutOfMemory mem)exception..
What I'm after is a generic catch().
Thanks