RE: .NET has a broken Exception model
Even simpler, replace
if ( ((e as FormatException ) != null) || ((e as ArgumentExcepti on) != null) || ((e as OverflowExcepti on) != null) ) {
with
if ( (e is FormatException ) || (e is ArgumentExcepti on) || (e is OverflowExcepti on) ) {
-Chris
--------------------[color=blue]
>Newsgroups: microsoft.publi c.dotnet.genera l
>From: clyon@online.mi crosoft.com ("Chris Lyon [MSFT]")
>Organization : Microsoft
>Date: Tue, 11 May 2004 00:17:24 GMT
>Subject: RE: .NET has a broken Exception model
>X-Tomcat-NG: microsoft.publi c.dotnet.genera l
>MIME-Version: 1.0
>Content-Type: text/plain
>Content-Transfer-Encoding: 7bit
>
>Hi Cody
>
>You could try this:
>
> try {
> return new DateTime(int.Pa rse(tbYear.Text ), int.Parse(tbMon th.Text), int.Parse(tbDay .Text));
> }
> catch (Exception e) {
>
> if ( ((e as FormatException ) != null) || ((e as ArgumentExcepti on) != null) || ((e as OverflowExcepti on) != null) ) {
> // do stuff here
> } else {
> throw e;
> }
> }
>
>This will catch all the exceptions in one place, and rethrow anything you didn't want to catch (like OutOfMemoryExce ption, for example).
>
>Also, VB.NET has exception filtering, not unlike how you described below.
>
>Hope that helps!
>-Chris
>
>--------------------[color=green]
>>Reply-To: "cody" <no_spam_deutro nium@gmx.net>
>>From: "cody" <no_spam_deutro nium@gmx.net>
>>Subject: .NET has a broken Exception model
>>Date: Mon, 10 May 2004 17:40:29 +0200
>>Lines: 50
>>X-Priority: 3
>>X-MSMail-Priority: Normal
>>X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
>>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
>>Message-ID: <#ij77ZqNEHA.16 16@TK2MSFTNGP12 .phx.gbl>
>>Newsgroups: microsoft.publi c.dotnet.genera l
>>NNTP-Posting-Host: jendata.cravi.d e 213.238.41.40
>>Path: cpmsftngxa10.ph x.gbl!TK2MSFTFE ED01.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGP1 2.phx.gbl
>>Xref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.genera l:133578
>>X-Tomcat-NG: microsoft.publi c.dotnet.genera l
>>
>>public DateTime Value
>>{
>> get
>> {
>> try
>> {
>> return new DateTime(int.Pa rse(tbYear.Text ), int.Parse(tbMon th.Text),
>>int.Parse(tbD ay.Text));
>> }
>> catch (FormatExceptio n)
>> {
>> // do stuff here
>> }
>> catch (ArgumentExcept ion)
>> {
>> // do stuff here
>> }
>> catch (OverflowExcept ion)
>> {
>> // do stuff here
>> }
>>}
>>
>>Since there is no good base class (No, I won't catch System.Exceptio n) I
>>have to catch all three exceptions separately. If all three exceptions
>>requires the same error handling I have to write the code three times or
>>have to create a separate method only for this stupid small exception
>>handling.
>>
>>Why not one single base-class for all non-fatal SystemException s?
>>
>>There are many other examples, e.g. a simple call to Process.Start which can
>>throw 4 different exceptions which I have to deal with
>>(InvalidOpera tion,Argument,W in32,ObjectDisp osed).
>>
>>Please MS, revise your exception model!
>>
>>If MS cannot handle this, please allow at least a syntax like
>>
>>catch (ArgumentExcept ion,OverflowExc eption,FormatEx ception)
>>{
>>}
>>
>>--
>>cody
>>
>>Freeware Tools, Games and Humour
>>http://www.deutronium.de.vu || http://www.deutronium.tk
>>
>>
>>[/color]
>
>
>--
>
>This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
>http://www.microsoft.com/info/cpyright.htm
>
>Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
>[/color]
--
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
Even simpler, replace
if ( ((e as FormatException ) != null) || ((e as ArgumentExcepti on) != null) || ((e as OverflowExcepti on) != null) ) {
with
if ( (e is FormatException ) || (e is ArgumentExcepti on) || (e is OverflowExcepti on) ) {
-Chris
--------------------[color=blue]
>Newsgroups: microsoft.publi c.dotnet.genera l
>From: clyon@online.mi crosoft.com ("Chris Lyon [MSFT]")
>Organization : Microsoft
>Date: Tue, 11 May 2004 00:17:24 GMT
>Subject: RE: .NET has a broken Exception model
>X-Tomcat-NG: microsoft.publi c.dotnet.genera l
>MIME-Version: 1.0
>Content-Type: text/plain
>Content-Transfer-Encoding: 7bit
>
>Hi Cody
>
>You could try this:
>
> try {
> return new DateTime(int.Pa rse(tbYear.Text ), int.Parse(tbMon th.Text), int.Parse(tbDay .Text));
> }
> catch (Exception e) {
>
> if ( ((e as FormatException ) != null) || ((e as ArgumentExcepti on) != null) || ((e as OverflowExcepti on) != null) ) {
> // do stuff here
> } else {
> throw e;
> }
> }
>
>This will catch all the exceptions in one place, and rethrow anything you didn't want to catch (like OutOfMemoryExce ption, for example).
>
>Also, VB.NET has exception filtering, not unlike how you described below.
>
>Hope that helps!
>-Chris
>
>--------------------[color=green]
>>Reply-To: "cody" <no_spam_deutro nium@gmx.net>
>>From: "cody" <no_spam_deutro nium@gmx.net>
>>Subject: .NET has a broken Exception model
>>Date: Mon, 10 May 2004 17:40:29 +0200
>>Lines: 50
>>X-Priority: 3
>>X-MSMail-Priority: Normal
>>X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
>>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
>>Message-ID: <#ij77ZqNEHA.16 16@TK2MSFTNGP12 .phx.gbl>
>>Newsgroups: microsoft.publi c.dotnet.genera l
>>NNTP-Posting-Host: jendata.cravi.d e 213.238.41.40
>>Path: cpmsftngxa10.ph x.gbl!TK2MSFTFE ED01.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGP1 2.phx.gbl
>>Xref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.genera l:133578
>>X-Tomcat-NG: microsoft.publi c.dotnet.genera l
>>
>>public DateTime Value
>>{
>> get
>> {
>> try
>> {
>> return new DateTime(int.Pa rse(tbYear.Text ), int.Parse(tbMon th.Text),
>>int.Parse(tbD ay.Text));
>> }
>> catch (FormatExceptio n)
>> {
>> // do stuff here
>> }
>> catch (ArgumentExcept ion)
>> {
>> // do stuff here
>> }
>> catch (OverflowExcept ion)
>> {
>> // do stuff here
>> }
>>}
>>
>>Since there is no good base class (No, I won't catch System.Exceptio n) I
>>have to catch all three exceptions separately. If all three exceptions
>>requires the same error handling I have to write the code three times or
>>have to create a separate method only for this stupid small exception
>>handling.
>>
>>Why not one single base-class for all non-fatal SystemException s?
>>
>>There are many other examples, e.g. a simple call to Process.Start which can
>>throw 4 different exceptions which I have to deal with
>>(InvalidOpera tion,Argument,W in32,ObjectDisp osed).
>>
>>Please MS, revise your exception model!
>>
>>If MS cannot handle this, please allow at least a syntax like
>>
>>catch (ArgumentExcept ion,OverflowExc eption,FormatEx ception)
>>{
>>}
>>
>>--
>>cody
>>
>>Freeware Tools, Games and Humour
>>http://www.deutronium.de.vu || http://www.deutronium.tk
>>
>>
>>[/color]
>
>
>--
>
>This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
>http://www.microsoft.com/info/cpyright.htm
>
>Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
>[/color]
--
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
Comment