Exception Chaining (raise … from)
say it: “RAYZ FRUM” /ˈreɪz ˈfrʌm/ or “ik-SEP-shun CHAY-ning” /ɪkˈsɛpʃən ˈtʃeɪnɪŋ/
Raising a clearer error while keeping the original attached (raise ... from).
What is exception chaining?
Exception chaining (raise … from) raises a new, clearer error while keeping the original one attached, so the traceback shows both.
def load_price(text):
try:
return float(text)
except ValueError as error:
raise ValueError(f"Bad price in file: {text!r}") from error
Level: Journeyman · More Python terms at this level
Updated