Do Nested try: ... except: 's work?
Chad Everett
chat at linuxsupreme.homeip.net
Fri Jun 15 17:27:27 EDT 2001
On Fri, 15 Jun 2001 19:10:38 -0000, jestes39 at yahoo.com <jestes39 at yahoo.com> wrote:
>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
>
>
import telnetlib
import exceptions
class no_connect(exceptions.Exception):
def __init__(self,args=None):
self.args = args
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'
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
More information about the Python-list
mailing list