Why exceptions for error handling is so important

Tobias Pankrath via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 16 04:38:58 PST 2015


>
> IMO, this example just shows that it's a bad idea to follow the 
> "exceptions are for exceptional circumstances only" mantra too 
> strictly. The call to `file_exists()` serves no other purpose 
> than to make the exception truly exceptional, otherwise it's 
> completely superfluous (well, aside from performance concerns, 
> but these are implementation details). Simply leave it out and 
> only rely on the exception, it really isn't evil.

1. Exception are too slow
2. They're used for exceptional cases only, they're fast enough 
for this
1. But look here, my file handling code might very well throw an 
exception, if the file already exists.

--> Use of a very slow operation, probably involving a spinning 
disk, at least a system call, to argue that exceptions are too 
slow does not convince me, sorry.


More information about the Digitalmars-d mailing list