[Python-Dev] Exception masking/chaining
Tue, 10 Jun 2003 21:09:44 +0200
Brett C. wrote:
> Brett C. wrote:
>> Greg Ewing wrote:
>>>> can we now consider implementing chained exceptions as has been
>>>> mentioned here numerous times?
>>> I must have missed that. What are chained exceptions?
>> This was discussed on the list between Ping and I think Walter (could
>> be wrong about Walter but I know Ping was involved). Should be in the
>> Summary archive somewhere; just need to find it. =)
> Found it.
> Raymond apparently instigated the thread:
> And it continued into the next month:
> And you even contributed to the discussion, Greg =) :
> But the original terminology was "exception masking" so that may have
> been why this didn't ring any bells.
> For the impatient you can read the last 3 emails I think (especially the
> absolute last which was authored by Raymond) to get a summary of the
> ideas proposed.
An open question for exception chaining was which exception type is
tested in the except statement, the innermost or the outermost one.
I'd say for backwards compatibility reasons this should be the outermost
exception, but we could add a new feature to that: Add a new exception
subclass named Info that can be used to wrap exceptions without
influencing the type of the exception raised. This could be used
by code higher up in the call chain to add information to the
exception without changing the type that gets caught in the except
statement. For example filter() could be changed to add information
about the iteration index where the exception happened:
def __getitem__(self, index):
x = filter(None, spam())
this might give:
Traceback (most recent call last):
File "spam.py", line 8, in ?
x = filter(None, foo())
File "spam.py", line 4, in __getitem__
Info: in filter() at index 42