Challenge: Custom Exception for Business Rules
Taak
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.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 2
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Geweldig!
Completion tarief verbeterd naar 4.17
Challenge: Custom Exception for Business Rules
Veeg om het menu te tonen
Taak
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.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 2
single