Raising, Custom Exceptions & Chaining — Concept Check
Questions on Raising, Custom Exceptions & Chaining. raise signals failure; custom exception classes give your domain a vocabulary; raise...from chains causes so tracebacks tell the whole story.
Questions in this quiz
7 questions on Raising, Custom Exceptions & Chaining — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer wants to catch all payment-related issues in their application. Which exception should they catch?
- ABaseException
- BCardDeclined
- CGatewayTimeout
- DPaymentError
2.You attempt to charge a card with an amount exceeding the limit, and a CardDeclined exception is raised. What will be printed?
- A'payment failed, alerting ops...'
- B'specific: card declined'
- C'specific: limit exceeded'
- D'some other payment issue'
3.A developer uses 'raise X from e' in their code. What is the benefit of this approach?
- AIt converts the exception to a warning.
- BIt preserves the original exception cause in the traceback.
- CIt suppresses the original exception cause.
- DIt logs the exception automatically.
4.In a payment processing system, a CardDeclined exception is raised but not caught specifically. What happens next?
- AThe program terminates immediately.
- BThe exception is ignored silently.
- CA default handler logs the error.
- DThe exception is propagated up the call stack.
5.Why should you inherit custom exceptions from Exception and not BaseException?
- ABaseException is meant for user-defined exceptions.
- BBaseException provides more detailed error messages.
- CException is deprecated in favor of BaseException.
- DBaseException is intended for system-exiting exceptions.
6.A developer mistakenly believes that 'raise' inside an 'except' block creates a new exception. What actually happens?
- AIt logs the current exception and continues execution.
- BIt suppresses the current exception.
- CIt creates a new exception with a new traceback.
- DIt re-raises the current exception.
7.When chaining exceptions, what phrase appears in the traceback to indicate the relationship?
- A'The following exception was the indirect cause...'
- B'The above exception occurred due to...'
- C'The following exception was caused by...'
- D'The above exception was the direct cause...'