Re: What am I doing wrong here?

Discussion in 'Python' started by =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Jun 30, 2003.

  1. Bill C. Wong wrote:

    > ################################
    > def func( s ):
    > s1, s2 = s.split( ' ', 1 )
    > try:
    > raise s1
    > except "aaaa":
    > print 'except "aaaa"'
    > except:
    > print 'except:'
    >
    > s = "aaaa "
    > func( s )
    > ################################
    > If I manually assign s1 with s1 = "aaaa", then it works fine! What am I
    > doing wrong here?


    Ok, looking closer this looks like your fault, not Python's:

    Please read http://python.org/doc/current/ref/try.html

    which states for the first parameter of the except clause:

    """Note that the object identities must match, i.e. it must be the same
    object, not just an object with the same value."""

    The lesson learnt is to *not* use string exceptions. String exceptions
    are terrible outdated and quite frankly suck. If you want to create a
    custom exception, subclass Exception and catch this class.

    -- Gerhard
     
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Jun 30, 2003
    #1
    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. Miguel Dias Moura
    Replies:
    1
    Views:
    425
  2. Jeremy Watts

    what am i doing wrong here?

    Jeremy Watts, Jun 4, 2005, in forum: Java
    Replies:
    12
    Views:
    578
    Jeremy Watts
    Jun 5, 2005
  3. Replies:
    9
    Views:
    22,837
  4. =?ISO-8859-1?Q?Gerhard_H=E4ring?=

    Re: What am I doing wrong here?

    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Jun 30, 2003, in forum: Python
    Replies:
    1
    Views:
    718
    Bengt Richter
    Jun 30, 2003
  5. Aahz
    Replies:
    0
    Views:
    622
Loading...

Share This Page