I frequently find that I want to raise an exception when the target of a call
is not in an appropriate state to perform the requested operation. Rather than
choosing between `Exception` or defining a custom exception, it would be nice
if there were a built-in `InvalidStateError` exception that
Le 01/09/2022 à 23:40, Steve Jorgensen a écrit :
I frequently find that I want to raise an exception when the target of a call
is not in an appropriate state to perform the requested operation. Rather than
choosing between `Exception` or defining a custom exception, it would be nice
if there
Matthias Görgens wrote:
> > If the target of the call isn't in an appropriate state, isn't that a
> > bug in the constructor that it allows you to construct objects that are
> > in an invalid state?
> > You should fix the object so that it is never in an invalid state rather
> > than blaming the
On Thu, Sep 01, 2022 at 09:40:05PM -, Steve Jorgensen wrote:
> I frequently find that I want to raise an exception when the target of
> a call is not in an appropriate state to perform the requested
> operation. Rather than choosing between `Exception` or defining a
> custom exception, it
On Fri, 2 Sept 2022 at 10:51, Steve Jorgensen wrote:
>
> Matthias Görgens wrote:
> > > If the target of the call isn't in an appropriate state, isn't that a
> > > bug in the constructor that it allows you to construct objects that are
> > > in an invalid state?
> > > You should fix the object so
On Thu, Sep 1, 2022, 9:12 PM Chris Angelico
> > It depends on context whether it makes sense to define a custom
> exception, and I agree that I frequently should define a custom exception.
> In that case though, it would still be nice to have an appropriate generic
> exception for that to inherit
>
> If the target of the call isn't in an appropriate state, isn't that a
> bug in the constructor that it allows you to construct objects that are
> in an invalid state?
>
> You should fix the object so that it is never in an invalid state rather
> than blaming the caller.
>
You can't really do
Matthias Görgens wrote:
> > If the target of the call isn't in an appropriate state, isn't that a
> > bug in the constructor that it allows you to construct objects that are
> > in an invalid state?
> > You should fix the object so that it is never in an invalid state rather
> > than blaming the
On Thu, Sep 1, 2022 at 2:57 PM Jean Abou Samra wrote:
>
> How would
> a "state error" differ from this more precisely? What value would this new
> exception type add? Both ValueError and this proposed StateError are very
> generic.
>
Some examples:
* a stream-like object that has been closed
Paul Moore wrote:
> What's wrong with defining a custom exception? It's literally one line:
> `class InvalidStateError(Exception): pass`. Two lines if you want to put
> the `pass` on its own line.
> The built in exceptions are ones that are raised by the core interpreter.
> Even the stdlib doesn't
Java calls this IllegalStateException so I would suggest IllegalStateError.
Looking at other exceptions that Java has, it would also be nice to
have UnsupportedOperationError (I have used NotImplementedError for this
but that suggests it might someday be implemented).
On the other hand, as you
What's wrong with defining a custom exception? It's literally one line:
`class InvalidStateError(Exception): pass`. Two lines if you want to put
the `pass` on its own line.
The built in exceptions are ones that are raised by the core interpreter.
Even the stdlib doesn't get builtin exceptions,
Jean Abou Samra wrote:
> Le 01/09/2022 à 23:40, Steve Jorgensen a écrit :
> > I frequently find that I want to raise an exception when the target of a
> > call is not in an appropriate state to perform the requested operation.
> > Rather than choosing between `Exception` or defining a custom
13 matches
Mail list logo