Python Migration Error: TypeError: exceptions must be old-style classes or derived from BaseException, not str
Wong Wah Meng-R32813
r32813 at freescale.com
Mon Oct 3 03:51:52 EDT 2011
More information about the Python-list mailing list
Mon Oct 3 03:51:52 EDT 2011
- Previous message (by thread): Python Migration Error: TypeError: exceptions must be old-style classes or derived from BaseException, not str
- Next message (by thread): Python Migration Error: TypeError: exceptions must be old-style classes or derived from BaseException, not str
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Noted. No choice then, I will convert all my raise statement to use the exception instance. Thanks! Regards, Wah Meng -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Monday, October 03, 2011 3:46 PM To: Wong Wah Meng-R32813 Cc: python-list at 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 <r32813 at 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
- Previous message (by thread): Python Migration Error: TypeError: exceptions must be old-style classes or derived from BaseException, not str
- Next message (by thread): Python Migration Error: TypeError: exceptions must be old-style classes or derived from BaseException, not str
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list