Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: What am I doing wrong here? (http://www.velocityreviews.com/forums/t319006-re-what-am-i-doing-wrong-here.html)

=?ISO-8859-1?Q?Gerhard_H=E4ring?= 06-30-2003 03:35 AM

Re: What am I doing wrong here?
 
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



All times are GMT. The time now is 12:41 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.