Chaining Custom Exceptions

Mon 10 August 2026
class InitialError(Exception):
    pass

class DerivedError(Exception):
    pass

try:
    try:
        raise InitialError("Initial failure")
    except InitialError as e:
        raise DerivedError("Follow-up failure") from e
except DerivedError as final_error:
    print(final_error)
Follow-up failure


Score: 10

Category: chapter7_custom_exceptions