By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,770 Members | 1,799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,770 IT Pros & Developers. It's quick & easy.

Exceptions handling

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> 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().


catch(Exception e) catches all exceptions. You might want to read up on
"finally" as well.

Here is a tutorial on exception handling:
http://www.programmersheaven.com/2/les_csharp_9_p1

Laban

Nov 17 '05 #2

P: n/a
Hello ___Newbie___" d,

Read this article

http://msdn.microsoft.com/library/de...ceptdotnet.asp

_> 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
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 17 '05 #3

P: n/a
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

Nov 17 '05 #4

P: n/a
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


Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.