Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Guard Clauses with Custom Exceptions | Custom Exceptions and Guard Clauses
C# Exceptions and Error Handling Practice
close
Sektion 2. Kapitel 6
single

single

bookChallenge: 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

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 6
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

some-alt