[Tutor] Stack unwind using exceptions.

Eike Welk eike.welk at gmx.net
Sun Jul 5 23:29:45 CEST 2009


On Sunday 05 July 2009, Noufal Ibrahim wrote:
> Kent Johnson wrote:
> [..]
>
> > Why not just return the value from the function and pass it up
> > the call chain? If a call fails return None. Something like this:
>
> That's what I ended up doing but the first thing occurred to me and
> I was just wondering if there's any production code that relies on
> the technique.

The Pyparsing library uses exceptions a lot internally. 

If I understood it right, exceptions are used to tell that a pattern 
does not match. If the pattern matches the results are transported 
with a regular 'return'. As it happens quite often that a pattern 
does not match, exceptions can be considered a regular mechanism for 
information transport in Pyparsing.

There are two types of exceptions in Pyparsing. An exception that 
means: try the next pattern; and there are exceptions that mean: 
there was a fatal error, stop parsing.

Pyparsing:
http://pyparsing.wikispaces.com/


Kind regards,
Eike.


More information about the Tutor mailing list