Re: [Tutor] Subclassing Exceptions

2012-01-09 Thread Chris Fuller
On Friday 06 January 2012, Steven D'Aprano wrote: > Chris Fuller wrote: > class Foo(SyntaxError): > > ... def __init__(self, a,b,c): > > ... self.args = (a,b,c) > > ... > > > raise Foo(1,2,3) > > > > Traceback (most recent call last): > > File "", line 1, in > > > > __main__.Foo:

Re: [Tutor] Subclassing Exceptions

2012-01-07 Thread Lie Ryan
On 01/07/2012 03:56 PM, Steven D'Aprano wrote: Chris Fuller wrote: You probably shouldn't inherit from SyntaxError, since it represents syntax errors in the Python code being interpreted or compiled. Any syntax error in your own data structures should be independent of SyntaxError. I'd say a s

Re: [Tutor] Subclassing Exceptions

2012-01-06 Thread Steven D'Aprano
Devin Jeanpierre wrote: Inheriting from SyntaxError doesn't work! When I create a new exception, I generally subclass from the built-in exception it most resembles, in case there was some reason to also catch it via an ancestor. But I'm not sure if that is really all that useful an idea in prac

Re: [Tutor] Subclassing Exceptions

2012-01-06 Thread Steven D'Aprano
Chris Fuller wrote: class Foo(SyntaxError): ... def __init__(self, a,b,c): ... self.args = (a,b,c) ... raise Foo(1,2,3) Traceback (most recent call last): File "", line 1, in __main__.Foo: None Inheriting from SyntaxError doesn't work! When I create a new exception, I generally sub

Re: [Tutor] Subclassing Exceptions

2012-01-06 Thread Devin Jeanpierre
> Inheriting from SyntaxError doesn't work! When I create a new exception, I > generally subclass from the built-in exception it most resembles, in case > there was some reason to also catch it via an ancestor. But I'm not sure if > that is really all that useful an idea in practice. How do you

[Tutor] Subclassing Exceptions

2012-01-06 Thread Chris Fuller
I had an interesting experience today. Python 2.7.1 (r271:86832, Nov 28 2010, 19:31:37) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(Exception): ... def __init__(self, a,b,c): ... self.args = (a,b,c) ... >>> raise Foo(1,2,3) Traceb