On 13.11.13 14:51, nick.coghlan wrote:

http://hg.python.org/cpython/rev/854a2cea31b9
changeset:   87084:854a2cea31b9
user:        Nick Coghlan <ncogh...@gmail.com>
date:        Wed Nov 13 23:49:21 2013 +1000
summary:
   Close #17828: better handling of codec errors

- output type errors now redirect users to the type-neutral
   convenience functions in the codecs module
- stateless errors that occur during encoding and decoding
   will now be automatically wrapped in exceptions that give
   the name of the codec involved

Wouldn't it be better to add an annotation API to the exceptions classes? This would allow to annotate all exceptions without having to replace the exception object.

I.e. BaseException would have an additional method annotate():

   try:
      dostuff(param)
   except Exception as exc:
      exc.annotate("while doing stuff with {}".format(param))

annotate() would simply append the message to an internal list attribute.

BaseException.__str__() could then use this to format an appropriate exception message.

Servus,
   Walter

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to