Challenge: Guard Clauses with Custom Exceptions
Task
Swipe to start coding
Implement a method for a product ordering system that enforces stock limits using guard clauses and a custom exception.
- If the requested quantity is greater than the available stock, the method must throw an
OutOfStockException. - If the requested quantity is within the available stock, the stock must be reduced by the ordered quantity.
Solution
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 6
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 4.17
Challenge: Guard Clauses with Custom Exceptions
Swipe to show menu
Task
Swipe to start coding
Implement a method for a product ordering system that enforces stock limits using guard clauses and a custom exception.
- If the requested quantity is greater than the available stock, the method must throw an
OutOfStockException. - If the requested quantity is within the available stock, the stock must be reduced by the ordered quantity.
Solution
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 6
single