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

Lie Lie.1296 at gmail.com
Mon Mar 10 19:47:54 CET 2008


On Mar 10, 12:12 pm, John Nagle <na... at animats.com> wrote:
> Steven D'Aprano wrote:
> > On Sat, 08 Mar 2008 22:24:36 -0800, Kay Schluehr wrote:
>
> >> On 9 Mrz., 06:30, Steven D'Aprano <st... at REMOVE-THIS-
> >> cybersource.com.au> wrote:
> >> Is it really so exotic that it requires the demand for more use cases?
>
> > Are the existing solutions really so incomplete that we need yet another
> > solution?
>
> > What problem are you trying to solve with SoftExceptions?
>
>     I actually implemented something like "soft exceptions" in a LISP
> program long ago. I called them "gripes".  They were a way that a function
> could complain about something it wanted the caller to fix. The caller
> could either fix it or decline to do so.
>
>     This was for a robotic planning application, where one module had detected
> that some precondition that it needed wasn't satisfied.  This was usually
> something like some physical object being in the wrong place for a later
> operation, and a previously planned move needed to be modified. Passing
> the problem back to the caller sometimes allowed an easy fix, rather than
> aborting the whole plan and building a new one.
>
>     This isn't a common problem.
>
>     In the rare cases that it is needed, it can be implemented with callbacks.
> It doesn't require a language extension.
>
>                                         John Nagle

The problem with callbacks is that it works only for a small amount of
callbacks, it'd be too messy to have twenty different callbacks.
And the ultimate problem with callbacks is that we can't determine
from the outside whether the operation should continue or breaks at
the point of the callback without some messy trick.

We can't always determine whether we want to do this:
def somefunc(argA, argB, callback = DO_NOTHING):
    if argA == argB:
        callback()

or this:
def somefunc(argA, argB, callback = DO_NOTHING):
    if argA == argB:
        callback()
        return

perhaps we could do this:
    if argA == argB:
        if callback() == True: return

but that's so much extra codes written and would've been too messy to
write.

And actually this isn't a rare cases, and in fact is very common. It's
just that most cases that can be more cleanly written in
SoftException, can usually be handled in different ways, using tricks
that range from subtle to messy (like callbacks).



More information about the Python-list mailing list