The Right Approach to Exceptions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Feb 18 13:14:04 PST 2012


On 2/18/12 1:27 PM, Alex Rønne Petersen wrote:
> Point taken. I suggested GetOptException initially because, based on
> usage patterns of std.getopt, it seems to be most common to just catch
> the exception (be it a parsing error, type coercion error, or whatever)
> and print it.

In fact for the vast majority of exceptions it seems to be most common 
to just catch the exception and print it.

Tutorial examples never help, either. They go something like:

try {
   ... stuff ...
} catch (DatabaseException e) {
   print("There was a database exception: ", e);
} catch (NetworkException e) {
   print("There was a network exception: ", e);
}

etc.

Andrei


More information about the Digitalmars-d mailing list