The Right Approach to Exceptions

Patrick Down patrick.down at using.that.google.mail.thing.com
Sun Feb 19 13:36:29 PST 2012


Andrei Alexandrescu Wrote:

> On 2/18/12 4:26 PM, Jonathan M Davis wrote (abridged):
> GetOptException
> FlagArgumentMissingException
> InvalidFlagArgumentException
> UnknownFlagException
> FileException
> FileNotFoundException
> NotFileException
> NotDirException
> AccessDeniedException
> 
> I died inside a little.
> 
> Andrei
> 

As a lurker watching this debate with interest I just had an idea out of the blue idea that may or may not have value but might reduce the desire to create a new exception type Exception type for every error. 

What if the catch syntax was extended to take both a type and a condition.  

try {
  write(filename, ...);
}
catch(FileException e; e.errno == EEXIST) {
}
catch(FileException e; e.errno == EROFS) {
}

I realize that this is just syntactic sugar for catch(...) { if(...) {}} feel free to shoot it down.




More information about the Digitalmars-d mailing list