Re: an idea: "letter bombs"

Bennett Todd (bet@std.sbi.com)
Thu, 16 Dec 1993 14:28:22 -0500 (EST)

Bennett Todd (that's me!) writes:
>[...] And since the default behavior of an open() invocation is to emit
>an error message and die, I'd rather leave the code uncluttered. If,
>for a final production delivery, you want to have the error message
>look more like a traditional Unix message, I guess I'd wrap the whole
>program in a try/except pair that catches errors and formats a suitable
>message. In fact, I'd probably write (and use in every program) a
>routine to take the exception stack trace info, extract a short
>expression of where the error occurred, and print a message, probably
>like
>
> cat: open error on filename: no such file or directory
>
>or thereabouts. If the open() invocation were down in a subroutine, I'd
>be tempted to put the list of subroutine names, separated by ``:'', after
>the program name, as a highly-abbreviated stack trace.

Then I read my own words, and a thought hit me: __THERE'S__ a feature I'd
desperately love to see built into Python. Howabout if, by default, the
error message printed when Python exits due to an unhandled exception looked
like a standard Unix error message, after the fashion of perror(3)? If you
want it to send out the full debugging stack trace, perhaps a command-line
arg could restore the current behavior? Maybe -D?

If it doesn't get implemented, I wouldn't whine too loudly; I'd just go
ahead and build a boilerplate that acts that way. But it'd be seriously cool
if the behavior of a trivially-coded, obvious program with no error checking
was also the behavior of a perfect, Unix-issues-conscious program with
complete error checking and conventional error messages!

A couple of years ago, before I mastered Perl, I used to write lots of stuff
in C. I wrote a library, which I called libbent, which was mostly wrappers
around most of the Unix system calls and library routines that I used;
instead of calling fopen(), I'd call efopen(), and so on. These routines
would exit with an error message if anything went wrong, so I didn't need to
code all that tedious error checking into every program I wrote.

One of the things that impresses me the most about Python is that you don't
have to explicitly code those damned tests, it bombs off with a message if
an error occurs and you don't explicitly _do_something_ about it. If that
message were a conventional error message, rather than a stack trace, it'd
make Python awesomely comfortable for all the little scripting jobs that pop
up. I think.

-Bennett
bet@sbi.com