Challenge: Custom Exception for Business Rules
Task
Swipe to start coding
Create a custom exception and use it to enforce a business rule in a banking scenario. Your goal is to prevent negative deposit amounts by throwing a custom exception when such an attempt is made.
- Throw a
NegativeDepositExceptionif theamountpassed to theDepositmethod is less than zero. - Do not change the account balance if the exception is thrown.
- If the deposit is valid, add the
amountto the account balance.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 2
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Can you explain that in more detail?
What are the main benefits or drawbacks?
Can you give me an example?
Awesome!
Completion rate improved to 4.17
Challenge: Custom Exception for Business Rules
Swipe to show menu
Task
Swipe to start coding
Create a custom exception and use it to enforce a business rule in a banking scenario. Your goal is to prevent negative deposit amounts by throwing a custom exception when such an attempt is made.
- Throw a
NegativeDepositExceptionif theamountpassed to theDepositmethod is less than zero. - Do not change the account balance if the exception is thrown.
- If the deposit is valid, add the
amountto the account balance.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 2
single