473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Exceptions handling

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
4 1453
> 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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Zunbeltz Izaola | last post by:
Hi, I've the following problem with try/exception. I've a try block that will raise some exceptions. I want the program to ignore this exceptions completely. Is it possible? Thanks in...
16
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
13
by: kelvSYC | last post by:
What I want to do is to read a 32-bit unsigned integer (let's call that u32) in little-endian form from an fstream. Would it be better if my function went like this: // returns false if an...
59
by: kk_oop | last post by:
Hi. I wanted to use exceptions to handle error conditions in my code. I think doing that is useful, as it helps to separate "go" paths from error paths. However, a coding guideline has been...
6
by: Iain | last post by:
Hey folks, (I posted this in microsoft.public.dotnet.csharp.general yesterday, but it appears that this group is rather more lively) For the application I am developing, I have a data access...
16
by: Einar Høst | last post by:
Hi, I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some...
6
by: Leslie | last post by:
I am attempting to handle errors by using Application_Error. This seems to work fine in most situations. However, if the exception occurs during the Application_Start method, the stand error...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
18
by: Denis Petronenko | last post by:
Hello, in the following code i have segmentaion fault instead of exception. Why? What i must to do to catch exceptions in such situation? Used compiler: gcc version 3.3.6 (Debian 1:3.3.6-13) ...
5
by: adam.timberlake | last post by:
I've just finished reading the article below which goes into some depth about exceptions. The article was rather lucid and so I understand how to implement it all, the thing I'm having trouble with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.