Why exceptions for error handling is so important

Tobias Müller via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 12 10:06:19 PST 2015


"H. S. Teoh via Digitalmars-d" <digitalmars-d at puremagic.com> wrote:
> On Mon, Jan 12, 2015 at 05:22:26PM +0000, Adam D. Ruppe via Digitalmars-d wrote: 
>> I still wouldn't use them for ordinary flow as a general rule though,
>> but I think they work well for cases where you ask a function to do
>> something and it just can't.
> 
> Yeah, exceptions are supposed to be ... well, *exceptions*, rather than
> the norm. :-) If you're using exceptions to do flow control, you're
> doing something wrong.

But what's exceptional for you is normal for me.

C#'s Dictionary has TryGetValue that returns a bool in addition to the
normal indexing operator []  that throws, exactly for that reason. And this
is no exception (no pun intended), there are several cases like that in C#.
IMO there's something wrong if you have to resort to such code
duplification.


More information about the Digitalmars-d mailing list