471,350 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

simple try/except question

Is the behavior below expected?
If so, why is the exception not caught?
Thanks,
Alan Isaac
>>x,y='',''
try: x/y
.... except TypeError: print 'oops'
....
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'str' and 'str'
Oct 29 '07 #1
6 1202
Is the behavior below expected?
If so, why is the exception not caught?
Thanks,
Alan Isaac
>>>x,y='',''
try: x/y
... except TypeError: print 'oops'
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'str' and 'str'
A typo in your code? It works for me(tm)...

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>x,y = '',''
try: x/y
.... except TypeError: print 'oops'
....
oops

-tkc

Oct 29 '07 #2
On 29 oct, 12:46, Alan Isaac <ais...@american.eduwrote:
Is the behavior below expected?
If so, why is the exception not caught?
Thanks,
Alan Isaac
>x,y='',''
try: x/y

... except TypeError: print 'oops'
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'str' and 'str'
It works for me, using 2.5.1 and 2.4.3 on Windows XP.
Perhaps you reassigned TypeError?
Python 2.5 says:

pyTypeError
<type 'exceptions.TypeError'>

Earlier versions:
pyTypeError
<class exceptions.TypeError at 0x009B4570>

--
Gabriel Genellina

Oct 29 '07 #3
Tim Chase wrote:
It works for me(tm)...
Python 2.4.3
Sorry to have left out that detail.
Yes, it works for me in Python 2.4,
but not in 2.5.1.

The code I posted was copyied from the interpreter.

Alan Isaac
Oct 29 '07 #4
Tim Chase wrote:
It works for me(tm)...
Python 2.4.3
Sorry to have left out that detail.
Yes, it works for me in Python 2.4,
but not in 2.5.1.

The code I posted was copyied from the interpreter.

Alan Isaac
Oct 29 '07 #5
False alarm.
Fresh start of interpreter and all is well.
Apologies.
Still tracking.
Alan
Oct 29 '07 #6
Gabriel Genellina wrote:
Perhaps you reassigned TypeError?
Yes, that was it.
Sheesh.

Thanks!
Alan
Oct 29 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Nick Jacobson | last post: by
51 posts views Thread by Alan | last post: by
reply views Thread by 42 | last post: by
2 posts views Thread by main() | last post: by
24 posts views Thread by Michael | last post: by
30 posts views Thread by galiorenye | last post: by
6 posts views Thread by beantaxi | last post: by
5 posts views Thread by fussfart | last post: by
26 posts views Thread by optimistx | last post: by
17 posts views Thread by Chris M. Thomasson | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.