Re: [Python-Dev] Chained Exceptions

2005-05-14 Thread Brett C.
Guido van Rossum wrote: > [Brett C.] > >>Maybe, but as long as caught exceptions get cleared that should be an issue. >>Would this be solved if, when an 'except' branch is exited, exceptions are >>cleared? So, in the above example, once the 'pass' is hit in catchit() no >>exception is considered

Re: [Python-Dev] Chained Exceptions

2005-05-13 Thread Guido van Rossum
[Brett C.] > Maybe, but as long as caught exceptions get cleared that should be an issue. > Would this be solved if, when an 'except' branch is exited, exceptions are > cleared? So, in the above example, once the 'pass' is hit in catchit() no > exception is considered active any longer. This coul

Re: [Python-Dev] Chained Exceptions

2005-05-13 Thread Brett C.
Guido van Rossum wrote: > [Guido] > >>>What if that method catches that exception? > > > [Ka-Ping Yee] > >>Did you mean something like this? >> >>def handle(): >>try: >>open('spamspamspam') >>except: >>catchit() >># point A >>.

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Guido van Rossum
[James Y Knight ] > I think it's a bad idea to have this happen automatically. Many times > if an exception is raised in the except clause, that doesn't > necessarily imply it's related to the original exception. It just > means there's a bug in the exception handler. Yeah, but especially in that

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Delaney, Timothy C (Timothy)
James Y Knight wrote: > Of course you can already do similar with current python, it just > can't be spelled as nicely, and the default traceback printer won't > use the info: > > try: >raise AError > except: >newException = BError() >newException.cause=sys.exc_info() >raise newEx

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread James Y Knight
On May 12, 2005, at 6:32 PM, Ka-Ping Yee wrote: > Suppose exceptions have an optional "context" attribute, which is > set when the exception is raised in the context of handling another > exception. Thus: > > def a(): > try: > raise AError > except: > r

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Guido van Rossum
[Guido] > > What if that method catches that exception? [Ka-Ping Yee] > Did you mean something like this? > > def handle(): > try: > open('spamspamspam') > except: > catchit() > # point A > ... > > def catchit(): > t

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Guido van Rossum
[Phillip J. Eby] > I think the main problem is going to be that (IIUC), Python doesn't "know" > when you've exited an 'except:' clause and are therefore no longer > handling the exception. But the compiler knows and could insert code to maintain this state. > sys.exc_info() still gives you the e

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Phillip J. Eby
At 07:36 PM 5/12/2005 -0500, Ka-Ping Yee wrote: >On Thu, 12 May 2005, Brett C. wrote: > > Guido van Rossum wrote: > > > Try to come up with a precise specification and we'll talk. > > > > If a new exception is raised (e.g., not a bare 'raise') while a current > > exception is active (e.g., sys.exc_

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Ka-Ping Yee
On Thu, 12 May 2005, Guido van Rossum wrote: > Define "raise". Does that involve a raise statement? Not necessarily; it could be a raise statement or an inadvertently triggered exception, such as in the example code i posted. > What about 1/0? That counts. > What if you call a method that execu

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Guido van Rossum
[Brett C.] > If a new exception is raised (e.g., not a bare 'raise') while a current > exception is active (e.g., sys.exc_info() would return something other than a > tuple of None), then the new exception is made the active exception and the > now > old exception is assigned to the new exception'

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Ka-Ping Yee
On Thu, 12 May 2005, Brett C. wrote: > Guido van Rossum wrote: > > Try to come up with a precise specification and we'll talk. > > If a new exception is raised (e.g., not a bare 'raise') while a current > exception is active (e.g., sys.exc_info() would return something other > than a tuple of None)

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Brett C.
Guido van Rossum wrote: > [Ka-Ping Yee] > >>Suppose exceptions have an optional "context" attribute, which is >>set when the exception is raised in the context of handling another >>exception. Thus: >> >>def a(): >>try: >>raise AError >>except: >>raise

Re: [Python-Dev] Chained Exceptions

2005-05-12 Thread Guido van Rossum
[Ka-Ping Yee] > Suppose exceptions have an optional "context" attribute, which is > set when the exception is raised in the context of handling another > exception. Thus: > > def a(): > try: > raise AError > except: > raise BError > > yields an excepti

[Python-Dev] Chained Exceptions

2005-05-12 Thread Ka-Ping Yee
Suppose exceptions have an optional "context" attribute, which is set when the exception is raised in the context of handling another exception. Thus: def a(): try: raise AError except: raise BError yields an exception which is an instance of BError.