Raising with context
Learn in depth →raise from connects an application error to the lower-level failure that caused it.
raise DomainError("message") from errorExample
try:
try:
int("bad")
except ValueError as error:
raise RuntimeError("invalid record") from error
except RuntimeError as error:
print(type(error.__cause__).__name__)Result
ValueError
Watch for: Do not swallow failures or expose secrets in messages. Preserve enough context for diagnosis.
Practise this topic →