[Python-ideas] exception instantiation philosophy and practice [was: Let try-except check the exception instance]
Chris Angelico
rosuav at gmail.com
Thu May 31 14:03:57 EDT 2018
On Fri, Jun 1, 2018 at 12:52 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Thu, 31 May 2018 07:49:58 -0700
> Ethan Furman <ethan at stoneleaf.us> wrote:
>> On 05/31/2018 07:36 AM, Nick Coghlan wrote:
>>
>> > The exception machinery deliberately attempts to avoid instantiating exception objects whenever it can, but that gets
>> > significantly more difficult if we always need to create the instance before we can decide whether or not the raised
>> > exception matches the given exception handler criteria.
>>
>> Why is this? Doesn't the exception have to be instantiated at some point, even if just to print to stderr?
>
> Nick is talking about exceptions that are ultimately silenced,
> especially when caught from C code. You're right that, once caught
> from Python code, the exception *has* to be instantiated (since it is
> bound to a user-visible variable).
>
Big and common example: Loop termination by raising StopIteration.
ChrisA
More information about the Python-ideas
mailing list