Exception programming difficult

Nathan M. Swan nathanmswan at gmail.com
Mon Aug 13 01:00:31 PDT 2012


On Sunday, 12 August 2012 at 03:02:50 UTC, Marco Leise wrote:
> I just got a bit frustrated and wanted to say that I like 
> working with Exceptions in Java a lot more.

I don't. When writing a simple command line program, when there's 
an error, it usually means the user messed up and I can't 
recover. I just print the message and terminate. I don't want to 
have to write "throws Exception" for everything.

void main(string[] args) {
     try {
         realMain(args);
         return 0;
     } catch (Exception e) {
         stderr.writeln(e.msg);
     }
}

The idea sounds nice, but it's annoying in practice. The point of 
exceptions is to _centralize_ error handling. Being forced to 
either catch or declare is almost as bad as C-style errno error 
handling.

Perhaps an annotation might be nice, as long as it doesn't force 
catching:

void buggyFunction(string file, int exception) 
@throws(StdioException);


More information about the Digitalmars-d mailing list