maximum recursion depth exceeded

Jp Calderone exarkun at intarweb.us
Tue Mar 4 14:32:33 EST 2003


On Tue, Mar 04, 2003 at 11:52:36AM -0700, Mike Romberg wrote:
> 
>   I'm attempting to try and gracefully handle situations where
> infinite recursion can occur in scripts supplied to our system by our
> users.  To do this I've tried the following:
> 
> 
> try:
>     eval("Some code which might recurse")
> except exceptions.RuntimeError:
>     # Handle error
> 
>   When I supply a string which causes infinite recursion, I see these
> messages on the console:
> 
> Exception exceptions.RuntimeError: 'maximum recursion depth exceeded'
> in  ignored
> 
>   But I can't seem to catch the exceptions.  Is there something
> special about this exception?  Or am I just missing something obvious
> (which I have been know to do from time to time).
> 

  Something else may be going on.  Consider this:

     Python 2.2.2 (#4, Feb 27 2003, 16:59:21) 
     [GCC 2.95.3 20010315 (release)] on linux2
     Type "help", "copyright", "credits" or "license" for more information.
     >>> try:
     ...   (lambda x: x(x))(lambda x: x(x))
     ... except RuntimeError, e:
     ...   print 'Caught:', e
     ... 
     Caught: maximum recursion depth exceeded

  I see the same behavior in 2.1.3 and 2.3a2.  What version of Python are
you using?  Perhaps there is one where this is somehow treated differently.

  Also, what code are you running?  Perhaps it handles the exception,
preventing your code from ever seeing it.

  Jp

-- 
It is practically impossible to teach good programming style to
students that have had prior exposure to BASIC: as potential
programmers they are mentally mutilated beyond hope of
regeneration.        -- Dijkstra
-- 
 up 1 day, 11:58, 7 users, load average: 0.31, 0.20, 0.14





More information about the Python-list mailing list