Challenge: Custom Exception for Business Rules
Aufgabe
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.
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 2
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Suggested prompts:
Can you explain that in more detail?
What are the main benefits or drawbacks?
Can you give me an example?
Großartig!
Completion Rate verbessert auf 4.17
Challenge: Custom Exception for Business Rules
Swipe um das Menü anzuzeigen
Aufgabe
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.
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 2
single