Why exceptions for error handling is so important

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 12 09:54:53 PST 2015


On Mon, Jan 12, 2015 at 05:22:26PM +0000, Adam D. Ruppe via Digitalmars-d wrote:
> On Monday, 12 January 2015 at 13:54:18 UTC, Ola Fosheim Grøstad wrote:
> >What makes you say that?
> 
> try/throw/catch is like 50x slower than doing nothing except returning
> a value, but D's exceptions still tend to outperform Java and C#; it
> isn't awful.

It's a lot better now, but D exceptions used to be orders of magnitude
slower than Java's. There's an interesting little history of D exception
performance here:

	https://issues.dlang.org/show_bug.cgi?id=9584


> 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.

Still, #9584 had some discussions about doing lazy stack trace
construction, which was costing most of the time, but I don't remember
if that was actually implemented.


T

-- 
We are in class, we are supposed to be learning, we have a teacher... Is
it too much that I expect him to teach me??? -- RL


More information about the Digitalmars-d mailing list