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



On Sat, 08 Mar 2008 19:51:24 -0800, Lie wrote:

Soft Exception
What is "Soft Exception"?
Soft Exception is an exception that if is unhandled, pass silently as if
nothing happened. For example, if a variable turns into NoneType, it'll
raise Soft Exception that it have become NoneException, programmers that
wants to handle it can handle it with a try...except block while
programmers that doesn't care about it (or know it won't be a problem to
his code) can just leave the code as it is.

Soft Exception differs from Hard Exceptions (the regular Exception) in a
way that Hard Exception must be handled at all cost or the program will
be terminated while Soft Exception allow programmers not to handle it if
they don't want to.

I don't think that there are very many cases where exceptions can be
ignored safely. There are two main reasons for using exceptions:

(1) Signaling an exceptional event.

(2) An error occurred.

I can't think of many cases where you would wish to ignore either, and
just continue processing. The only examples I can think of are in loops,
where you are doing the same thing over and over again with just a little
change, and you wish to skip any problematic data, e.g.:

def plot_graph(func, domain):
for x in domain:
plot(x, func(x))

If an error occurs in plot() for one particular x value, you would want
to ignore it and go on to the next point. But that's easy enough to do
with a regular try...except block.

Simply put, you're suggesting the following two alternatives:

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.

The cost of explicitly silencing exceptions is tiny, the risk of misuse
of Soft Exceptions is very high, and the benefit of them is negligible.


--
Steven
.



Relevant Pages

  • Re: What c.l.pys opinions about Soft Exception?
    ... Exception can be added to the language silentlyso that new ... programmers doesn't _need_ to know about it (although knowing it could ... Soft Exception is an exception that if is unhandled, ... clumping be done on force calculation level, ...
    (comp.lang.python)
  • What c.l.pys opinions about Soft Exception?
    ... What is "Soft Exception"? ... Soft Exception is an exception that if is unhandled, ... programmers that wants to handle it can handle it with a try...except ... Exception can only be handled by codes above it while Event-based ...
    (comp.lang.python)
  • Re: What c.l.pys opinions about Soft Exception?
    ... Soft Exception is an exception that if is unhandled, ... programmers that wants to handle it can handle it with a try...except ... a `raise SoftException` in the middle of a loop would break the loop if a catcher existed, or leave the loop running if not. ...
    (comp.lang.python)
  • Re: What c.l.pys opinions about Soft Exception?
    ... > Soft Exception is an exception that if is unhandled, ... highest level, then filtering which exceptions would be stopped (Soft ... execution continues as if the 'raise' never happened. ...
    (comp.lang.python)
  • Re: Question concerning object-oriented programming
    ... there has usually been a toString. ... I would prefer an exception thrown. ... Actual programmers are supposed to write code that verifies input. ... Educated middle-class people learn how to use language to ...
    (comp.programming)