OOP - how to abort an __init__ when the initialisation code fails ?
Gregory Ewing
greg.ewing at canterbury.ac.nz
Thu Nov 7 07:06:05 EST 2019
Oscar Benjamin wrote:
> In Python the original exception message plus traceback is often very
> informative (to a programmer!) about the problem.
That's okay, exception chaining preserves the whole traceback if
you want to dig down that far.
> Catching and
> reraising can mean that you end up crafting an error message somewhere
> higher up where the filename isn't known any more.
Well, the idea is to catch it some place where the filename *is*
known. And when reraising, only add to the error message rather
than replacing it altogether, so once the filename is in there
it stays there, even if another catch-and-reraise occurs higher
up.
--
Greg
More information about the Python-list
mailing list