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 get builtin exceptions, look at sqlite3.Error, for
> example. Defining a custom exception in the module alongside the function
> that raises it is both normal practice, and far more discoverable.
> Paul
> On Thu, 1 Sept 2022 at 22:42, Steve Jorgensen stevec...@gmail.com 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
> > would be nice if there were a built-in `InvalidStateError` exception that
> > my code could raise.
> > In cases where I want to define a custom exception anyway, I think it
> > would be nice if it could have a generic `InvalidStateError` exception
> > class for it to inherit from.
> > Of course, I would be open to other ideas for what the name of this
> > exception should be. Other possibilities off the top of my head are
> > `BadStateError` or `StateError`.
> > _______________________________________________
> > Python-ideas mailing list -- python-ideas@python.org
> > To unsubscribe send an email to python-ideas-le...@python.org
> > https://mail.python.org/mailman3/lists/python-ideas.python.org/
> > Message archived at
> > https://mail.python.org/archives/list/python-ideas@python.org/message/NMHNKS...
> > Code of Conduct: http://python.org/psf/codeofconduct/
> >
OK, but by that logic, why do we have standard exceptions like `ValueError`
when we could define custom exceptions for the cases where that should be
raised?
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/5JGBBE7JEKWYPEQO6NC4B7UFKJN2UK6K/
Code of Conduct: http://python.org/psf/codeofconduct/