Mailing List Archive

Change SystemError to NOT inherit from Exception
A SystemError is typically raised from C to indicate serious bugs in the
application which shouldn't normally be caught and handled. It's used
for example for NULL arguments where a Python object is expected. So in
some sense, SystemError is the Python equivalent of a segmentation fault.

Since these exceptions should typically not be handled in a try/except
Exeption block, I suggest to make SystemError inherit directly from
BaseException instead of Exception.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/XA2A33CKERYELYPJS6GKVHCQAXOQKG5M/
Re: Change SystemError to NOT inherit from Exception [ In reply to ]
On 01.07.2019 12:25, Jeroen Demeyer wrote:
> A SystemError is typically raised from C to indicate serious bugs in the application which shouldn't normally be caught and handled. It's
> used for example for NULL arguments where a Python object is expected. So in some sense, SystemError is the Python equivalent of a
> segmentation fault.
>
> Since these exceptions should typically not be handled in a try/except Exeption block, I suggest to make SystemError inherit directly from
> BaseException instead of Exception.

https://docs.python.org/3/library/exceptions.html#SystemError:

> Raised when the interpreter finds an internal error, but the situation does not look so serious to cause it to abandon all hope. <...>
>
> You should report this to the author or maintainer of your Python interpreter.
For cases where the interpreter deems it too dangerous to continue, there's Py_FatalError().

And if it's safe to continue, the exception can be handled -- and since no-one specifically expecs SystemError, will be either logged, or
ignored if the author explicitly doesn't mind if the particular code fails -- whether for this reason or any other.

--

Regards,
Ivan
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/5AFZBPYFCUB6JQV4G2OKE36WJVPJ55A3/
Re: Change SystemError to NOT inherit from Exception [ In reply to ]
There's two issues with this idea.

One, backwards-compatibility, especially since the only good way to handle this would be to modify the exception-handling code to recognize this specific case during deprecation.

But two, this would be a semantic shift of what classes directly inherit from `BaseException`. If you look at https://docs.python.org/3/library/exceptions.html#exception-hierarchy you will see that the only classes that inherit directly are ones that represent control flow. Adding `SystemError` to that list would make it a unique error condition that doesn't inherit from `Exception`.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/3VRHKHDIFO74Z6CLUX4G7VES6XJHLOTT/
Re: Change SystemError to NOT inherit from Exception [ In reply to ]
On 2019-07-02 23:29, Brett Cannon wrote:
> But two, this would be a semantic shift of what classes directly inherit from `BaseException`.

It depends how you interpret that. I always interpreted classes
inheriting directly from BaseException as exceptions that you almost
never want to catch in an "except Exception" block.

> Adding `SystemError` to that list would make it a unique error condition that doesn't inherit from `Exception`.

I would argue that the various exception classes inheriting from
BaseException are already quite unique: a KeyboardInterrupt is very
different from a GeneratorExit for example.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/U7CDZYS7WMJ2EIS3PQCE7WQMKUT7FFX6/
Re: Change SystemError to NOT inherit from Exception [ In reply to ]
Jeroen Demeyer wrote:
> On 2019-07-02 23:29, Brett Cannon wrote:
> > But two, this would be a semantic shift of what
> > classes directly inherit from BaseException.
> > It depends how you interpret that. I always interpreted classes
> inheriting directly from BaseException as exceptions that you almost
> never want to catch in an "except Exception" block.

As co-author of PEP 352 I can tell you the intent is the one I laid out. ;) (See https://www.python.org/dev/peps/pep-0352/#exception-hierarchy-changes.)

> > Adding SystemError to that list would
> > make it a unique error condition that doesn't inherit from Exception.
> > I would argue that the various exception classes inheriting from
> BaseException are already quite unique: a KeyboardInterrupt is very
> different from a GeneratorExit for example.

Depends on your view. To me they are both control flow; one is for generators, one is for whole applications, but the point of both is to bubble up a control flow shift as appropriate and not be caught by `except Exception` blocks.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/EQHW2CKD4WDKZWQBB3BFFYJP2N2TYSXB/