[Tutor] try..except - what about that ton of **Error statements?

boB Stepp robertvstepp at gmail.com
Wed May 22 18:50:34 CEST 2013


On Wed, May 22, 2013 at 9:45 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On 22/05/13 23:31, boB Stepp wrote:
>>
>> On Wed, May 22, 2013 at 7:50 AM, Steven D'Aprano <steve at pearwood.info>
>> wrote:

[...]

>>> 3) your job as a programmer is *not* to stop your program from raising an
>>> error, but to make it behave correctly -- sometimes an error is the right
>>> thing to do;
>>>
>>
>> Also, can you clarify this point as well? When would you want your
>> program to crash?
>
>
> You don't *want* it to crash, you would rather it exit gracefully. But a
> crash is better than silently doing the wrong thing.
>

Would you define "exiting gracefully"? It appears you mean a
controlled (by the programmer's code) exit that gives a meaningful (to
the user or the programmer?) error message instead of in an
uncontrolled manner where the only available information would be
whatever the OS generates.

> Some years ago there was a very unfortunate incident where a
> computer-controlled medical x-ray irradiated a large number of people with
> fatal doses of radiation. The machine should have halted with an error, but
> due to a combination of bad design, operator error, and programming bugs,
> instead it blasted the poor doomed patients with thousands of times the safe
> limit of radiation.
>

Thanks for the example! Unfortunately these devastating errors
continue. The New York Times has reported on some radiation therapy
incidents in the past few years, some of which were caused by
programming errors (along with the usual errors by the people using
the software).

> That's an extreme example, but the same principle applies in general. Your
> program has a job to do. If it cannot do that job correctly, it should own
> up to it rather than do something else. If you tell your program to save
> your work to a file, and the disk is full, what would you rather happen?
>

I like very much how you put this. Integrity in programming!

> - You get an error message, so you can make some space and try again.
>
> - The program silently discards your data, so it is not saved but you don't
> know it.
>
> - The program deletes other files at random until it has freed up enough
> space to save your data.
>
>
> Pick one.
>

I guess I'll pick the first alternative. However, this brings to mind
my biggest gripe as a user of software, particularly here at work
where the programmer obviously has no medical background: cryptic
error messages that might be meaningful to the programmer, but are
totally unhelpful to me, the user, who has to figure out what to do
next.

[...]

Thanks for the clarifications!

boB


More information about the Tutor mailing list