Re: Exception vs Boolean
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: 14 Aug 2006 01:42:08 -0700
Cor Ligthert [MVP] wrote:
In my idea is the well written text from Scott, completely clear.
This is interesting, given that his clarification suggests that your
interpretation was not what was actually meant...
In VB it is easy to tell.
Never use an exception in a Sub because than giving back a Boolean or an
enum is more describing and as Scott wrote less consuming processing time.
No, a boolean or enum is *not* more descriptive than an exception. An
exception can give as much information as you want it to - a boolean or
an enum is a single value. Furthermore, turning the sub into a function
with a status code then demands that every call to it should check the
status code (assuming they care about error handling).
Do you really want to have to check a status code every time you add an
entry to a list?
Performance is a separate issue - have you read my page on it? Do you
have any experience of real life situations where exceptions were only
thrown in ways which most people would deem "reasonable" but where
performance was an issue?
Decide in a function if you can give a class with an error code in it.
Although in this case is in my idea throwing an exception more describing.
Translating this to C# gives than the answer on the exact OP question, you
should never let a Void method throw an exception but use a method that
gives back a boolean (or enum).
Well, I'm very glad you weren't part of designing the framework
classes. You'll find very few status codes there, and plenty of
exceptions being thrown by void methods.
Jon
.
- Follow-Ups:
- Re: Exception vs Boolean
- From: Cor Ligthert [MVP]
- Re: Exception vs Boolean
- References:
- Re: Exception vs Boolean
- From: Scott M.
- Re: Exception vs Boolean
- From: Jon Skeet [C# MVP]
- Re: Exception vs Boolean
- From: Cor Ligthert [MVP]
- Re: Exception vs Boolean
- Prev by Date: Re: Add more scheme for Auto Format in Datagrid
- Next by Date: Re: Exception vs Boolean
- Previous by thread: Re: Exception vs Boolean
- Next by thread: Re: Exception vs Boolean
- Index(es):
Relevant Pages
|