Re: .NET has a broken Exception model
From: Stu Smith (stuarts_at_nospam-digita.com)
Date: 05/11/04
- Next message: Cor Ligthert: "Re: How do you set the current row in a dataset"
- Previous message: Craig: "Re: How do you set the current row in a dataset"
- In reply to: Tom Porterfield: "Re: .NET has a broken Exception model"
- Next in thread: Dave: "Re: .NET has a broken Exception model"
- Reply: Dave: "Re: .NET has a broken Exception model"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 11 May 2004 16:01:42 +0100
(inline)
"Tom Porterfield" <tpporter@mvps.org> wrote in message
news:OihGex0NEHA.736@TK2MSFTNGP09.phx.gbl...
> William Ryan eMVP wrote:
> > Tom:
> >
> > I think his whole point is that System.Exception is a lame approach
> > but not using it requires quite a bit of code for this situation.
> > Take Cody's example directly and say that based on those exceptions,
> > he returns lets say a return code of 0. Now, if something more
> > severe happens or is outside of the bounds there, say the classic
> > OutOfMemory exception, System.Exception is going to catch it and
> > return a 0. There would be no differentiation between the two. Do
> > this in a class library that you distribute and you could really
> > obscure some ugly bugs.
>
> Reread what I said. I said SystemException, not System.Exception. There
is
> a distinct difference. All exceptions inherit from System.Exception.
> System.SystemException is the base for non-fatal or recoverable
exceptions.
> The problem comes in when what one person considers recoverable someone
else
> may consider fatal.
It's probably best, to avoid a neverending argument, to distinguish between
two sorts of fatal vs non-fatal:
1) Fatal exceptions as defined by the framework. They are
OutOfMemoryException, ExecutionEngineException, and StackOverflowException.
You simply can't catch them, except possibly within the unhandled exception
handler.
2) Fatal within the context of a block of code. So in the current example,
FormatException, ArgumentException and OverflowException are being
considered as non-fatal (ie they aren't going to be allowed out of this
stack frame). All other exceptions are outside the scope of that block of
code, and will unwind until some other block of code considers itself
capable of dealing with them.
I tend to use "fatal" for case (1) but I suppose you could use it for case
(2).
Personally, in the case of this thread, I'd say the problem is that there is
no Int32.TryParse or DateTime.TryParse (cf Double.TryParse) in the
framework, as opposed to a shortcoming of the exception system.
Stu
>
> > Personally in this situation I trap all my exceptions specifically
> > and don't really have a problem b/c I seldom do the same things for
> > different exceptions (actually, I never do unless it's an oversight)
> > so it's not really an issue to me, but if I wanted to trap those four
> > things and respond the same way to each of them like he mentions,
> > then it would cause you to write some extraneous code. But catching
> > System.Exception in an instance like this seems to be the worst of
> > all worlds (I mean no offense by this, just MHO). You can't possibly
> > know/anticipate and respond specifically to every possible exception
> > under the sun and assuming one wanted to make the argument they could
> > (mathematically it's possible), you'd defintiely write a lot of code
> > that you didn't know.
>
> No offense taken as you didn't read my original message correctly.
>
> It really depends on what the requirement is. If you only care about four
> specific exceptions then you have to filter in some way, either with
> distinct catches or a more generic catch and then throw if the exception
> isn't what you wanted. Like just about any problem, this one has multiple
> solutions, all with their own merit.
> --
> Tom Porterfield
> MS-MVP MCE
> http://support.telop.org
>
> Please post all follow-ups to the newsgroup only.
>
- Next message: Cor Ligthert: "Re: How do you set the current row in a dataset"
- Previous message: Craig: "Re: How do you set the current row in a dataset"
- In reply to: Tom Porterfield: "Re: .NET has a broken Exception model"
- Next in thread: Dave: "Re: .NET has a broken Exception model"
- Reply: Dave: "Re: .NET has a broken Exception model"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|