Why exceptions for error handling is so important

via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 12 09:44:07 PST 2015


On Monday, 12 January 2015 at 17:22:27 UTC, Adam D. Ruppe 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.
>
> 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.
>
>> Doesn't D still use the standard zero-cost EH that was created 
>> for Itanium, where you take the performance hit on unwinding?
>
> I don't know, I'm just thinking about the bemchmarks.

Right, I kinda think that C++ EH is awful outside the context of 
big iron. It is often avoided.

I think a clean language should find one single way to deal with 
errors, so having one mechanism that performs well would make for 
clean programming.

I've suggested many alternatives before, at least 4. And D could 
do anything the hardware supports. Including having multiple 
return paths, efficient longjump, implicit errorcode propagation, 
offsetbased unwinding...

Error handling and GC are perhaps the two issues that are the 
major weak spots for D. I think the language could be changed 
somewhat and do both reasonably well (as well as one can with 
stop-the-world-GC).


More information about the Digitalmars-d mailing list