Try except - bug?

A

Askari

Hi,
I have a problem with try except :
example
============
try:
print "bou!"
raise "ha!"
except:
try:
fileDest.close()
except NameError:
print "error"
except:
import traceback
traceback.print_exc(file=sys.stdout)
============
If I run this example alone, I have no problem :
result
============
bou!
error
============

but I can't understand why doesn't work in my program :
http://www.cvm.qc.ca/9974331/Temp/crypte.py
(too long for a copy and paste)
(note : it's at line 353)
(note : the language of this program is in french, sorry)

when I run my program, I have this error :
============
Traceback (most recent call last):
File "C:\Documents and Settings\Assembleur_Man\Bureau\Crypte.py",
line 355, in crypte
fileDest.close()
NameError: global name 'fileDest' is not defined
============

but I know that 'fileDest' is not always defined but I put this line
in a try-except!? :-( :-S


Askari
 
A

Askari

(e-mail address removed) (Askari) wrote in
Hi,
I have a problem with try except :
example
============
try:
print "bou!"
raise "ha!"
except:
try:
fileDest.close()
except NameError:
print "error"
except:
import traceback
traceback.print_exc(file=sys.stdout)
============
If I run this example alone, I have no problem :
result
============
bou!
error
============

but I can't understand why doesn't work in my program :
http://www.cvm.qc.ca/9974331/Temp/crypte.py
(too long for a copy and paste)
(note : it's at line 353)
(note : the language of this program is in french, sorry)

when I run my program, I have this error :
============
Traceback (most recent call last):
File "C:\Documents and Settings\Assembleur_Man\Bureau\Crypte.py",
line 355, in crypte
fileDest.close()
NameError: global name 'fileDest' is not defined
============

but I know that 'fileDest' is not always defined but I put this line
in a try-except!? :-( :-S


Askari


Ops! For test (to do the error), you must click on button "crypter!" with
blank textField
 
R

Rene Pijlman

Askari:
but I can't understand why doesn't work in my program :
http://www.cvm.qc.ca/9974331/Temp/crypte.py [...]
when I run my program, I have this error :
============
Traceback (most recent call last):
File "C:\Documents and Settings\Assembleur_Man\Bureau\Crypte.py",
line 355, in crypte ^^^
fileDest.close()
NameError: global name 'fileDest' is not defined
============

That's strange, because there is no fileDest.close() on line 355. Are you
sure the message and the code you are showing us correspond?
 
R

Rene Pijlman

Askari:
Ops! For test (to do the error), you must click on button "crypter!" with
blank textField

The program runs fine and displays a dialogue with "!ERREUR! :: Vous devez
avoir un code pour l'encryption.".
 
A

Askari

Rene Pijlman said:
Askari:

The program runs fine and displays a dialogue with "!ERREUR! :: Vous devez
avoir un code pour l'encryption.".

It's at 355 or 363 the error...

============
Traceback (most recent call last):
File "C:\Documents and Settings\Assembleur_Man\Bureau\test.py", line 363, in c
rypte
os.remove(destination)
OSError: [Errno 2] No such file or directory: ''
============

at line 355 you have : "fileDest.close()"
and at line 363 you have : "os.remove(destination)"

What is your version of python? (I have 2.3.2)
Do you have "Traceback" message in console (when you see the dialog)?

Askari
 
R

Rene Pijlman

Askari:
OSError: [Errno 2] No such file or directory: ''

If I'm not mistaken this is another exception!?
at line 355 you have : "fileDest.close()"

No, line 355 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

#afficher confirmation
and at line 363 you have : "os.remove(destination)"

No, line 363 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

pass
What is your version of python? (I have 2.3.2)

I use UltraEdit 8.0 on Windows XP to count the line numbers.
 
A

Askari

Askari:
OSError: [Errno 2] No such file or directory: ''

If I'm not mistaken this is another exception!?
at line 355 you have : "fileDest.close()"

No, line 355 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:


#afficher confirmation
and at line 363 you have : "os.remove(destination)"

No, line 363 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

pass
What is your version of python? (I have 2.3.2)

I use UltraEdit 8.0 on Windows XP to count the line numbers.

euh.... I use UltraEdit 10.10 and "#afficher confirmation" is at line 349
(it's the same numero in IDLE). Are you sure that your UltraEdit is
correct? Check the line in IDLE, it's the same?
 
A

Askari

Askari:
OSError: [Errno 2] No such file or directory: ''

If I'm not mistaken this is another exception!?
at line 355 you have : "fileDest.close()"

No, line 355 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:


#afficher confirmation
and at line 363 you have : "os.remove(destination)"

No, line 363 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

pass
What is your version of python? (I have 2.3.2)

I use UltraEdit 8.0 on Windows XP to count the line numbers.

Batheme! I didn't know that the exception rest in memory after a "catch".
Finaly, it's my mistake with use of "sys.exc_info()" at line 368.

But for # of line; check your ultraedit. Are you sure that the line 1 is
"#! d:/python23/python" ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,174
Messages
2,570,940
Members
47,486
Latest member
websterztechnologies01

Latest Threads

Top