Patrick Maupin schrieb: > I'm a newbie when it comes to deep Python internals, so maybe I'm > missing something obvious. I'm trying to figure out the right answer > for exceptions/tracebacks in PEP 3101 (advanced string formatting).
You should turn the question then around: "This is what I want to display, how can I achieve that". This seems the tricky part here: What *is* it that you want to display? > However, it seems that the Python traceback scheme is intimately tied > to the concept of Python execution frames, which are assumed to have > associated text information from a file. I'm not sure that I can > legitimately add to a preexisting traceback from a C function in a > non-fragile fashion. Even if I could, I don't really have a "file" to > show the user (unless I dynamically create one). You can certainly add a stack frame into the traceback, see Modules/pyexpat.c (call_with_frame). However, this will get you just a function number, line number, etc: there is no exception object associated with the trace. > So it seems the only answer might have to have options like "let the > user see the existing traceback" or "get rid of the traceback and > raise an exception which shows exactly where in > the format string the error occured", or "print the preexisting > traceback to stderr, then toast it and raise a new exception showing > the string location in the exception text." I still don't understand why you worry about the stack trace. Isn't the exception object what you are after? > I guess there are two parts to my question: > > 1) What is the best thing to do right now for PEP3101? I may be repeating myself, but I think you are looking for some kind of nested exceptions. There is no notion of nested exceptions yet in Python, but you could try to implement some scheme, where the formatting exception has a reference to the "true" exception, and, when printing the formatting exception, the true exception and its traceback get printed. > 2) If the "right now" answer isn't very good, is this really a more > general problem that needs work? As more "little languages" do things > like manipulate the AST, it might become very useful to have the > ability to place almost arbitrary objects on the traceback stack. Same question again. The stack trace seems irrelevant in this problem to me, and so does 'putting objects on it'. Regards, Martin _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com