niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
new style exception handleing
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
Author Message
Nick Coghlan
*nix forums Guru Wannabe


Joined: 20 Feb 2005
Posts: 131

PostPosted: Thu Feb 03, 2005 10:17 am    Post subject: Re: new style exception handleing Reply with quote

Ola Natvig wrote:
Quote:
Peter Hansen wrote:
I can't actually think of a reason to need to base an
exception on a new-style class, but perhaps you have a
good one...

It's quite simple to bypass the problem, it was more the reason I was
wondering about too.

Basically because fixing it without killing backward compatibility with string
exceptions is hard :)

Doesn't mean people aren't trying though (Google the python-dev archives, as
well as the python-list ones).

Cheers,
Nick.

--
Nick Coghlan | ncoghlan@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Back to top
Michele Simionato
*nix forums Guru Wannabe


Joined: 20 Feb 2005
Posts: 253

PostPosted: Thu Feb 03, 2005 7:48 am    Post subject: Re: new style exception handleing Reply with quote

Google is your friend.
This has been discussed a lot in the past. For instance, google for the
thread,
"Exceptions as New Style Classes", there was also a PEP by Steven
Taschuk,
IIRC.

Michele Simionato
Back to top
Ola Natvig
*nix forums beginner


Joined: 02 Mar 2005
Posts: 18

PostPosted: Thu Feb 03, 2005 7:33 am    Post subject: Re: new style exception handleing Reply with quote

Peter Hansen wrote:
Quote:
Ola Natvig wrote:

Does anybody know why it's not possible to raise Exceptions which are
types (new-style-classes). I know all standard exceptions are classic
classes, but if you make a custom exception which both inherits from a
exception class and a new-style one the it causes a type error when
raised.

class b(Exception, object): pass


This might not help you, but have you considered just making
your old-style class *contain a reference* to an instance
of whatever new-style class you want it to contain? Then
the issue goes away.

I can't actually think of a reason to need to base an
exception on a new-style class, but perhaps you have a
good one...

-Peter

It's quite simple to bypass the problem, it was more the reason I was
wondering about too.

--
--------------------------------------
Ola Natvig <ola.natvig@infosense.no>
infoSense AS / development
Back to top
Peter Hansen
*nix forums Guru


Joined: 19 Feb 2005
Posts: 1153

PostPosted: Wed Feb 02, 2005 4:57 pm    Post subject: Re: new style exception handleing Reply with quote

Ola Natvig wrote:
Quote:
Does anybody know why it's not possible to raise Exceptions which are
types (new-style-classes). I know all standard exceptions are classic
classes, but if you make a custom exception which both inherits from a
exception class and a new-style one the it causes a type error when raised.

class b(Exception, object): pass

This might not help you, but have you considered just making
your old-style class *contain a reference* to an instance
of whatever new-style class you want it to contain? Then
the issue goes away.

I can't actually think of a reason to need to base an
exception on a new-style class, but perhaps you have a
good one...

-Peter
Back to top
Ola Natvig
*nix forums beginner


Joined: 02 Mar 2005
Posts: 18

PostPosted: Wed Feb 02, 2005 2:11 pm    Post subject: new style exception handleing Reply with quote

Hi all

Does anybody know why it's not possible to raise Exceptions which are
types (new-style-classes). I know all standard exceptions are classic
classes, but if you make a custom exception which both inherits from a
exception class and a new-style one the it causes a type error when raised.

Quote:
class b(Exception, object): pass

raise b

Traceback (most recent call last):
File "<pyshell#2>", line 1, in -toplevel-
raise b
TypeError: exceptions must be classes, instances, or strings
(deprecated), not type

This is weird, I think. Are there any issues about raising types as
exceptions that I can't think of ?


--
--------------------------------------
Ola Natvig <ola.natvig@infosense.no>
infoSense AS / development
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 10:17 pm | All times are GMT
navigation Forum index » Programming » python
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Win32::OLE and CAPICOM to find a certificate in certifica... dan2online Perl 0 Thu Jul 20, 2006 6:47 am
No new posts Win32::OLE and CAPICOM to find a certificate in certifica... dan2online modules 0 Thu Jul 20, 2006 6:44 am
No new posts Why dont RealTime Embedded programmers use Exception Hand... NewToCPP embedded 4 Mon Jul 17, 2006 8:46 pm
No new posts Why dont RealTime Embedded programmers use Exception Hand... NewToCPP C++ 5 Mon Jul 17, 2006 8:08 pm
No new posts registering class methods as C style callbacks noone@all.com C++ 11 Mon Jul 17, 2006 5:35 pm

Mortgage | Final Fantasy Wallpapers | Wikipedia | Repair Bad Credit | Credit Cards
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2250s ][ Queries: 20 (0.1397s) ][ GZIP on - Debug on ]