[Tutor] Nicer error message

Alan Gauld alan.gauld at btinternet.com
Tue May 31 19:26:12 CEST 2011


"Válas Péter" <sulinet at postafiok.hu> wrote

> You could write directly to sys.stderr instead of raising an error.

Or better still do both. But only at the top level of your program.

> > If other programmers have to work with your code, they'll probably
> > find this _incredibly_ annoying.
>
> You mean there is no way to write it nicely?
> Or are error messages not intended to be written on screen?

You need to distinguish between error messages and
exception tracebacks. The latter are intended to convey
useful debugging information to developers. The former
are intended to inform non tchniocal users of a problem
and what, if anything they can do about it.

In general you display error messages as part of handling
an exception. You may well do so at the top level of your program
where all hope of auto-recovering from the error has gone...

You may well also raise the exception so that the debug
output can go to stderr - which may well be redirected
to a log file somewhere. You may even, in the error message,
ask the user to email the logfile to a support desk....

But they are different things and serve different purposes.
Programs with exceptions and no error messages stand
a high chance of being rejected - witness the effect of
the blue screen of death on early Window NT adoption...
Presenting user friendly, clear information messages
about errors and detailed technical information to
developers keeps everyone happy (or if not actually
happy - it has crashed after all! - at least sane.)

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list