[Python-ideas] Improving Catching Exceptions

Nick Coghlan ncoghlan at gmail.com
Tue Jun 27 07:41:41 EDT 2017


On 27 June 2017 at 02:29, Sven R. Kunze <srkunze at mail.de> wrote:
> On 24.06.2017 01:37, MRAB wrote:
>>
>> I think a "shallow exception" would be one that's part of a defined API,
>> as distinct from one that is an artifact of the implementation, a leak in
>> the abstraction.
>
> I like the "shallow exception" idea most. It's simple and it covers most if
> not all issues. You also hit the nail with pointing to leaking abstractions.

The shallow exception notion breaks a fairly fundamental refactoring
principle in Python: you should be able to replace an arbitrary
expression with a subfunction or subgenerator that produces the same
result without any of the surrounding code being able to tell the
difference.

By contrast, Steven's exception_guard recipe just takes the existing
"raise X from Y" feature, and makes it available as a context manager
and function decorator.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list