[Tutor] User defined exceptions

Roel Schroeven roel at roelschroeven.net
Fri Oct 15 11:29:32 EDT 2021


Op 15/10/2021 om 13:43 schreef Alan Gauld via Tutor:
> You could go further and include a format string that inserts
> the actual value received. That would also speed up debugging:
>
> raise MarksError("Score of %d does not lie between 0 and 100" % score)
Yes! This is not done very often, and it often feels a bit like a chore. 
But it's so very useful in case of errors! IMO that advantage more than 
compensates for the extra effort.

-- 
"This planet has - or rather had - a problem, which was this: most of the
people living on it were unhappy for pretty much of the time. Many solutions
were suggested for this problem, but most of these were largely concerned with
the movement of small green pieces of paper, which was odd because on the whole
it wasn't the small green pieces of paper that were unhappy."
         -- Douglas Adams



More information about the Tutor mailing list