Do Nested try: ... except: 's work?

jestes39 at yahoo.com jestes39 at yahoo.com
Fri Jun 15 15:10:38 EDT 2001


I am trying to use the try: ... except: structure as it is used in 
Oracle for flow control. I am nesting try/except blocks and raising 
named excepts. Each time it gets to a raise statement that is 
referencing an except outside the current block, it fails and gives 
me an error similar to 'there is no variable named <except name>'.
Here is a short section to illustrate my point:

  import telnetlib

  try:
      try:
          tn = telnetlib.Telnet('xxx.xxx.xxx.xxx')
      except:
          no_connect_flag = 'TRUE'

      if no_connect_flag == 'TRUE':
          raise no_connect

      try:
          tn.set_debuglevel(100)
      except:
          print 'couldn''t set the debug level'
  except no_connect:
      print 'couldn''t open telnet connection'

When I run this script through the debugger, I get the error:
  
  NameError: There is no variable named 'no_connect'

Any help would be appreciated. Thanks.

jestes3 at logicon.com





More information about the Python-list mailing list