dereferencing null

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Mar 5 08:07:06 PST 2012


On Mon, Mar 05, 2012 at 02:30:14PM +0100, Andrej Mitrovic wrote:
> Personally I'd love to get more info about out-of-bounds errors. E.g.
> for arrays, which index the code attempted to access, and for hashes
> which key.

Personally, I'd love to see D's added string capabilities put to good
use in *all* exception messages. It's been how many decades since the
first C compiler was written? Yet we still haven't moved on from using
static strings in Exceptions. This is silly. A "file not found"
exception should tell you what the offending filename is. It's as simple
as:

	throw new IOException("File '%s' not found".format(filename));

A range violation should say what the offending index was:

[...]
>     enforce(key in aa, new RangeError(format(": Key %s not in hash. ", key)));
[...]
> core.exception.RangeError@: Key 1 not in hash. (20): Range violation

A numerical conversion error should say what the offending malformed
number was. Or at least, include the non-digit character that it choked
on.

A syntax error in getopt should tell you what the offending option was.
(How'd you like it if you ran some random program, and it says "command
line error" with no indication at all of what the error was?)

It's pure common sense. I mean, if the only message dmd ever gave was
"syntax error" without telling you *what* caused the syntax error or
*where* (file, line number, perhaps column), we'd all be beating down
Walter's door. So why should exceptions in other applications be any
different?


T

-- 
The volume of a pizza of thickness a and radius z can be described by
the following formula: pi zz a. -- Wouter Verhelst


More information about the Digitalmars-d mailing list