On 5/31/2018 12:47 AM, Danilo J. S. Bellini wrote:
Hi!
I was working on handling some exceptions from external software
(e.g. database constraint triggers)
switching the handler based on the messages that had been sent.
Today we can do something like (running on Python 3.6.5):


try:
...     # [...]
...     session.commit() # Here it raises!
...     # [...]
... except DatabaseError as exc:
...     msg = get_db_error_msg_from_exception(exc)
...     if msg == "beyond_limit":
...         # [...]
...     elif msg == "no_funds":
...         # [...]
...     else:
...         raise


That works,

Yes, it works perfectly well, AND it exposes the fact that your code depends on the message, which I think is a good thing.

As Stephen said, messages are intentionally not part of the defined API. As a matter of curtesy, we usually restrict message changes to new versions and do not backport the change. An exception may be made if we decide that a message is sufficiently erroneous that is likely misleads people. In any case, message dependent code may be version dependent.

--
Terry Jan Reedy


_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to