What c.l.py's opinions about Soft Exception?

Kay Schluehr kay.schluehr at gmx.net
Sun Mar 9 07:24:36 CET 2008


On 9 Mrz., 06:30, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:

> Hard Exceptions: terminate the program unless explicitly silenced
> Soft Exceptions: pass silently unless explicitly caught
>
> In this case, I agree with the Zen of Python ("import this"):
>
> Errors should never pass silently.
> Unless explicitly silenced.

Exceptions in Python don't necessarily signal errors. Just think about
StopIteration.

Note also that the common practice of letting *possible* errors passed
silently is to return None instead of raising an exception. Moreove
people create boilerplate like this

try:
   k = lst.index(elem)
   ...
except IndexError:
   pass

instead of

with lst.index(elem) as k:
    ...

It would be interesting to think about SoftException semantics for
such clauses: lst.index would neither raises a HardException nor does
it return None but leads to skipping the with-block.

Is it really so exotic that it requires the demand for more use
cases?



More information about the Python-list mailing list