simple try/except question

Discussion in 'Python' started by Alan Isaac, Oct 29, 2007.

  1. Alan Isaac

    Alan Isaac Guest

    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'
     
    Alan Isaac, Oct 29, 2007
    #1
    1. Advertising

  2. Alan Isaac

    Tim Chase Guest

    > 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
     
    Tim Chase, Oct 29, 2007
    #2
    1. Advertising

  3. On 29 oct, 12:46, Alan Isaac <> wrote:

    > 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:

    py> TypeError
    <type 'exceptions.TypeError'>

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

    --
    Gabriel Genellina
     
    Gabriel Genellina, Oct 29, 2007
    #3
  4. Alan Isaac

    Alan Isaac Guest

    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
     
    Alan Isaac, Oct 29, 2007
    #4
  5. Alan Isaac

    Alan Isaac Guest

    False alarm.
    Fresh start of interpreter and all is well.
    Apologies.
    Still tracking.
    Alan
     
    Alan Isaac, Oct 29, 2007
    #5
  6. Alan Isaac

    Alan Isaac Guest

    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
     
    Alan Isaac, Oct 29, 2007
    #6
  7. Alan Isaac

    Alan Isaac Guest

    Gabriel Genellina wrote:
    > Perhaps you reassigned TypeError?


    Yes, that was it.
    Sheesh.

    Thanks!
    Alan
     
    Alan Isaac, Oct 29, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Salerno
    Replies:
    20
    Views:
    866
    John Salerno
    Aug 11, 2006
  2. Fabio Z Tessitore

    who is simpler? try/except/else or try/except

    Fabio Z Tessitore, Aug 12, 2007, in forum: Python
    Replies:
    5
    Views:
    384
  3. Laszlo Nagy
    Replies:
    0
    Views:
    269
    Laszlo Nagy
    Feb 24, 2009
  4. David House

    try -> except -> else -> except?

    David House, Jul 6, 2009, in forum: Python
    Replies:
    2
    Views:
    352
    Bruno Desthuilliers
    Jul 6, 2009
  5. MRAB
    Replies:
    4
    Views:
    315
Loading...

Share This Page