473,385 Members | 1,325 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,385 software developers and data experts.

Exceptions: Order of Catch Statements?

Could someone provide me with a URL documenting the
specific order of exceptions?

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
Nov 15 '05 #1
8 3525
clintonG wrote:
Could someone provide me with a URL documenting the
specific order of exceptions?


From the most specific of your catch blocks to the most general. So an
exception of a specific type would be caught by a matching catch block
rather than a catch set up for something generic like Exception.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #2
Clinton,

I'm not sure that I understand what you are looking for -- but here are two
links
1) catching a thrown exception (straingt from the C# reference)
2) a second that provides good fuel for the recurring, requisite (albeit
pedantic) debate on exceptions that comes up at the weekly .Net cocktail
party

http://msdn.microsoft.com/library/en...pspec_16_3.asp

http://msdn.microsoft.com/library/en...rp07192001.asp

If this doesn't help, post back with a bit more info on what you are looking
for..

regards
roy fine
"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message
news:eU*************@TK2MSFTNGP11.phx.gbl...
Could someone provide me with a URL documenting the
specific order of exceptions?

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

Nov 15 '05 #3
Thank you Roy, I'm responding to Frank as he clued in
on 'specifics' which is pertinent to this discussion. Note however
that your [2] reference resulted in leading me to relevant criteria
that you may care to respond to if you climb back up the thread.

<%= Clinton Gallagher
"Roy Fine" <rl****@twt.obfuscate.net> wrote in message
news:#N**************@TK2MSFTNGP10.phx.gbl...
Clinton,

I'm not sure that I understand what you are looking for -- but here are two links
1) catching a thrown exception (straingt from the C# reference)
2) a second that provides good fuel for the recurring, requisite (albeit
pedantic) debate on exceptions that comes up at the weekly .Net cocktail
party

http://msdn.microsoft.com/library/en...pspec_16_3.asp
http://msdn.microsoft.com/library/en...rp07192001.asp

If this doesn't help, post back with a bit more info on what you are looking for..

regards
roy fine
"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message news:eU*************@TK2MSFTNGP11.phx.gbl...
Could someone provide me with a URL documenting the
specific order of exceptions?

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/


Nov 15 '05 #4

"Frank Oquendo" <fr****@acadxpin.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
clintonG wrote:
Could someone provide me with a URL documenting the
specific order of exceptions?


From the most specific of your catch blocks to the most general. So an
exception of a specific type would be caught by a matching catch block
rather than a catch set up for something generic like Exception.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)


Thanks for replying Frank. Your correct about specific-to-general
order of operations and I mentioned 'specific order' but was vague
when indicating I am asking how to actually determine specificity.

Using one of Roy's referrals to the C# Language Reference at MSDN
"How exceptions are handled" [1], I was able to use the sidebar menu
to navigate to "Common Exception Classes" [2]. Are we to assume those
common exception classes are listed top-down in order of specificity?
Indications do not support that assumption leaving the determination of
specificity to be determined by other means.

After posting the question -- which is usually the ways it goes -- I found
what seemed to be an answer in the "System Hierarchy" [3]. It seems we
should use the 'specific' derived classes such as DivideByZeroException
rather than the more 'general' ArithmeticException base class which is clear
enough but...

How for example is the developer to determine the specificity of using
DivideByZeroException as opposed to using FormatException?

I imagine one should attempt to catch a FormatException as the implied
circumstances suggest the developer would want to determine if the
correct data type had been submitted before attempting to use that data
in any operation. Thus FormatException would be more specific than
DivideByZeroException. Is this thinking correct?

What page of the documentation is experience listed on? :-)

[1]
http://msdn.microsoft.com/library/de...pspec_16_3.asp
[2]
http://msdn.microsoft.com/library/de...pspec_16_4.asp
[3]
http://msdn.microsoft.com/library/de...mhierarchy.asp

<%= Clinton Gallagher

Nov 15 '05 #5

"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message
news:e0**************@TK2MSFTNGP12.phx.gbl...

"Frank Oquendo" <fr****@acadxpin.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
clintonG wrote:
Could someone provide me with a URL documenting the
specific order of exceptions?
From the most specific of your catch blocks to the most general. So an
exception of a specific type would be caught by a matching catch block
rather than a catch set up for something generic like Exception.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)


Thanks for replying Frank. Your correct about specific-to-general
order of operations and I mentioned 'specific order' but was vague
when indicating I am asking how to actually determine specificity.

Using one of Roy's referrals to the C# Language Reference at MSDN
"How exceptions are handled" [1], I was able to use the sidebar menu
to navigate to "Common Exception Classes" [2]. Are we to assume those
common exception classes are listed top-down in order of specificity?
Indications do not support that assumption leaving the determination of
specificity to be determined by other means.

After posting the question -- which is usually the ways it goes -- I found
what seemed to be an answer in the "System Hierarchy" [3]. It seems we
should use the 'specific' derived classes such as DivideByZeroException
rather than the more 'general' ArithmeticException base class which is

clear enough but...

How for example is the developer to determine the specificity of using
DivideByZeroException as opposed to using FormatException?

I imagine one should attempt to catch a FormatException as the implied
circumstances suggest the developer would want to determine if the
correct data type had been submitted before attempting to use that data
in any operation. Thus FormatException would be more specific than
DivideByZeroException. Is this thinking correct?
They are different things and therefore have the same specificity. For this
example consider specificity as the distance from Exception. The further
away from Exception you are in the current family the more specific you are.
DivideByZeroException is more specific than ArithmeticException which is
more specific than SystemException which is more specific than Exception,
however a catch block of any of those types will catch an exception of type
DivideByZeroException. They are just less specific.
FormatException is more specific than SystemException, but is not related to
DivideByZeroException in any way.
What page of the documentation is experience listed on? :-)

[1]
http://msdn.microsoft.com/library/de...pspec_16_3.asp [2]
http://msdn.microsoft.com/library/de...pspec_16_4.asp [3]
http://msdn.microsoft.com/library/de...mhierarchy.asp
<%= Clinton Gallagher

Nov 15 '05 #6

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:uM**************@TK2MSFTNGP12.phx.gbl...

"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message news:e0**************@TK2MSFTNGP12.phx.gbl...

"Frank Oquendo" <fr****@acadxpin.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
clintonG wrote:
> Could someone provide me with a URL documenting the
> specific order of exceptions?

From the most specific of your catch blocks to the most general. So an
exception of a specific type would be caught by a matching catch block
rather than a catch set up for something generic like Exception.

--
There are 10 kinds of people. Those who understand binary and those who don't.

http://code.acadx.com
(Pull the pin to reply)
Thanks for replying Frank. Your correct about specific-to-general
order of operations and I mentioned 'specific order' but was vague
when indicating I am asking how to actually determine specificity.

Using one of Roy's referrals to the C# Language Reference at MSDN
"How exceptions are handled" [1], I was able to use the sidebar menu
to navigate to "Common Exception Classes" [2]. Are we to assume those
common exception classes are listed top-down in order of specificity?
Indications do not support that assumption leaving the determination of
specificity to be determined by other means.

After posting the question -- which is usually the ways it goes -- I found what seemed to be an answer in the "System Hierarchy" [3]. It seems we
should use the 'specific' derived classes such as DivideByZeroException
rather than the more 'general' ArithmeticException base class which is

clear
enough but...

How for example is the developer to determine the specificity of using
DivideByZeroException as opposed to using FormatException?

I imagine one should attempt to catch a FormatException as the implied
circumstances suggest the developer would want to determine if the
correct data type had been submitted before attempting to use that data
in any operation. Thus FormatException would be more specific than
DivideByZeroException. Is this thinking correct?

They are different things and therefore have the same specificity. For

this example consider specificity as the distance from Exception. The further
away from Exception you are in the current family the more specific you are. DivideByZeroException is more specific than ArithmeticException which is
more specific than SystemException which is more specific than Exception,
however a catch block of any of those types will catch an exception of type DivideByZeroException. They are just less specific.
FormatException is more specific than SystemException, but is not related to DivideByZeroException in any way.
What page of the documentation is experience listed on? :-)

[1]

http://msdn.microsoft.com/library/de...pspec_16_3.asp
[2]

http://msdn.microsoft.com/library/de...pspec_16_4.asp
[3]

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

<%= Clinton Gallagher


Sounds to me like you describe specificity as a subclassed hierarchical
relationship
of the System.Exception base class. When I see it that way as indicated via
[3] that
is what I need to confirm as careful reading of System.Exception states
"...a catch block
that handles a type must be specified before a catch block that handles its
base types..."
which really helps puts specificity into perspective.

<%= Clinton Gallagher
Nov 15 '05 #7
<snip>
They are different things and therefore have the same specificity. For

this
example consider specificity as the distance from Exception. The further
away from Exception you are in the current family the more specific you

are.
DivideByZeroException is more specific than ArithmeticException which is
more specific than SystemException which is more specific than Exception,
however a catch block of any of those types will catch an exception of

type
DivideByZeroException. They are just less specific.
FormatException is more specific than SystemException, but is not

related to
DivideByZeroException in any way.
What page of the documentation is experience listed on? :-)

[1]

http://msdn.microsoft.com/library/de...pspec_16_3.asp
[2]

http://msdn.microsoft.com/library/de...pspec_16_4.asp
[3]

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

<%= Clinton Gallagher


Sounds to me like you describe specificity as a subclassed hierarchical
relationship
of the System.Exception base class. When I see it that way as indicated

via [3] that
is what I need to confirm as careful reading of System.Exception states
"...a catch block
that handles a type must be specified before a catch block that handles its base types..."
which really helps puts specificity into perspective.
Ya, that isn't the clearest writing you'll see. If you try to compile
something like
try
{

}
catch (Exception)
{
}
catch (SecurityException)
{
}

the compiler will produce an error. The first handler an exception
encounters that can handle it will be called, C# merely attempts to force
you to write code without a bug like above(technically *EVERY* exception
would be caught by the first handler and the second would never be called).
Becauseof that you have to put more specific(further derived\subclassed)
exception handlers first. <%= Clinton Gallagher

Nov 15 '05 #8
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:e9**************@TK2MSFTNGP11.phx.gbl...
<snip>
>
They are different things and therefore have the same specificity. For this
example consider specificity as the distance from Exception. The further away from Exception you are in the current family the more specific you
are.
DivideByZeroException is more specific than ArithmeticException which
is more specific than SystemException which is more specific than

Exception, however a catch block of any of those types will catch an exception of

type
DivideByZeroException. They are just less specific.
FormatException is more specific than SystemException, but is not related
to
DivideByZeroException in any way.

> What page of the documentation is experience listed on? :-)
>
> [1]
>

http://msdn.microsoft.com/library/de...pspec_16_3.asp
> [2]
>

http://msdn.microsoft.com/library/de...pspec_16_4.asp
> [3]
>

http://msdn.microsoft.com/library/de...mhierarchy.asp
>
> <%= Clinton Gallagher


Sounds to me like you describe specificity as a subclassed hierarchical
relationship
of the System.Exception base class. When I see it that way as indicated

via
[3] that
is what I need to confirm as careful reading of System.Exception states
"...a catch block
that handles a type must be specified before a catch block that handles

its
base types..."
which really helps puts specificity into perspective.

Ya, that isn't the clearest writing you'll see. If you try to compile
something like
try
{

}
catch (Exception)
{
}
catch (SecurityException)
{
}

the compiler will produce an error. The first handler an exception
encounters that can handle it will be called, C# merely attempts to force
you to write code without a bug like above(technically *EVERY* exception
would be caught by the first handler and the second would never be

called). Becauseof that you have to put more specific(further derived\subclassed)
exception handlers first.
<%= Clinton Gallagher

I read myself to sleep again last night and learned exactly what you point
out Daniel.

<%= Clinton Gallagher

Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: mag31 | last post by:
Is there any way to find out if a particular .net function will throw an exception without first generating the exception? I am using structured exception handling i.e. try catch finally blocks...
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...
22
by: Drew | last post by:
How do I know which exceptions are thrown by certain methods? For example, reading a file might throw an IO Exception, etc. In Java, the compiler won't even let you compile unless you put your...
9
by: Steven Blair | last post by:
Hi, I need to catch exceotions on File.Delete() After checking the help, I have noticed that thgere are serevral Exceptions that can be thrown. My question is, should I catch all thes...
6
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
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...
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...
2
by: aspestrand | last post by:
Hi, just wondering if anybody can answer the following question as it doesn't seem to be anywhere in the C++ spec. What will print from the following statement? (note the order of the catch...
9
by: paul | last post by:
Hi I would like to extract all possible exceptions for a particular method. Ideally this would be a Visual Studio 2005 Add-In and would allow a developer to highlight a any method, pressing a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.