Feature Requests item #1182143, was opened at 2005-04-13 06:02 Message generated for change (Comment added) made by rhettinger You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1182143&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: None Status: Open Resolution: None Priority: 5 Submitted By: Sebastien de Menten (sdementen) Assigned to: Nobody/Anonymous (nobody) Summary: making builtin exceptions more informative Initial Comment: Using builtin exception information is tricky as it consists of: a) the type of exception (easily accessible) b) the args attribute = a 1 element tuple with a string 1st example: try: print foo except NameError, e: print e.args symbol = e.args[0][17:-16] print symbols ==> ("NameError: name 'foo' is not defined", ) foo It would be nicer to have: e.args = ("NameError: name 'foo' is not defined", "foo") The first element being the current string for backward compatibilty. ============================= 2nd example: try: (4).foo except NameError, e: print e.args ==> ("'int' object has no attribute 'foo'",) It would be nicer to have: e.args = ("'int' object has no attribute 'foo'", 4, "foo") Again, the first element being the current string for backward compatibilty. ============================= Moreover, in the documentation about Exception, I read """Warning: Messages to exceptions are not part of the Python API. Their contents may change from one version of Python to the next without warning and should not be relied on by code which will run under multiple versions of the interpreter. """ So even args could not be relied upon ! But it also means that there is no need to be backward compatible (I am playing devil's advocate, backward compatibility is important !) Seb ps: There may be problems (that I am not aware) with a) an exception keeping references to other objects b) C API that can throw only exceptions with strings c) a specific advantage of having strings only in builtin exceptions ---------------------------------------------------------------------- >Comment By: Raymond Hettinger (rhettinger) Date: 2005-06-02 20:33 Message: Logged In: YES user_id=80475 This looks like a good idea to me. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1182143&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com