Clean way to return error codes
Chris Angelico
rosuav at gmail.com
Mon Nov 21 03:18:08 EST 2016
On Mon, Nov 21, 2016 at 6:09 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> try:
> begin()
> except BeginError:
> print("error in begin")
> sys.exit(3)
Do you control the errors that are getting thrown?
class BeginExit(SystemExit, BeginError): pass
It'll behave like SystemExit, but still be catchable as BeginError.
(Or if BeginError isn't used anywhere else, it can itself be redefined
to inherit from SystemExit.)
ChrisA
More information about the Python-list
mailing list