OOP - how to abort an __init__ when the initialisation code fails ?

R.Wieser address at not.available
Tue Nov 5 04:42:15 EST 2019


Chris,

> "Control flow" is anything that changes the order that your code runs.

My apologies, I should have said "a control flow mechanism" /in this 
context/ (though I assumed that as implicite, as I quoted the text from the 
OP).

Case in point, the __init__ code (of a class object) can result in an 
exception, and I need to deal with it.  But I should /not/ wrap whole blocks 
of code into a "try ... except" construction - which definitily is what will 
happen when I want to catch, in the calling program, exceptions thrown by 
the object while its initialising.

So, I was wondering if the "a control flow mechanism" reference was aimed at 
something that would alleviate the above "you must, but you shouldn't" 
conundrum.

Regards,
Rudy Wieser




More information about the Python-list mailing list