Noted. No choice then, I will convert all my raise statement to use the 
exception instance. Thanks!

Regards,
Wah Meng

-----Original Message-----
From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert
Sent: Monday, October 03, 2011 3:46 PM
To: Wong Wah Meng-R32813
Cc: python-list@python.org
Subject: Re: Python Migration Error: TypeError: exceptions must be old-style 
classes or derived from BaseException, not str

On Sun, Oct 2, 2011 at 11:45 PM, Wong Wah Meng-R32813
<r32...@freescale.com> wrote:
> Hello guys,
>
> I am migrating my application from python 1.5.2 to 2.7.1. I encountered an 
> error when I run some commands (I put in debug statement however, not able to 
> trace down to which line of code that cause it to generate a lot of messages 
> in one second until my hard disk space is full. The error log I got in my log 
> file is as below:-
>
> Oct  3 14:12:41  ('Encountered exception while processing from', (0, 
> '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), <type 
> 'exceptions.TypeError'>, TypeError('exceptions must be old-style classes or 
> derived from BaseException, not str',))
>
> Does it mean in newer python I need to migrate all my Exception to non-string 
> based exception type?

Correct. You can no longer do merely `raise "Some error message"`. You
should instead raise an exception instance of the appropriate type;
e.g. `raise ValueError("foo must be positive")`.
It's advisable to read the NEWS / "What's New" documents for the
intervening versions so you can learn what else has changed.

> That's should be a lot of changes. :p

To be fair, v1.5.2 is practically ancient at this point. It's over a
decade old! And 2 *major* versions behind what's current.
In a pinch, you could always write a script to mechanically change
`raise "..."` to `raise StandardError("...")` [or some other fairly
generic exception type].

Cheers,
Chris


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to