Challenge: Guard Clauses with Custom Exceptions
Opgave
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.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 6
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Suggested prompts:
Can you explain this in simpler terms?
What are the main benefits or drawbacks?
Can you give me a real-world example?
Fantastisk!
Completion rate forbedret til 4.17
Challenge: Guard Clauses with Custom Exceptions
Stryg for at vise menuen
Opgave
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.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 6
single