Sektion 2. Kapitel 4
single
Challenge: Add Exception Throwing to a Function
Stryg for at vise menuen
Opgave
Swipe to start coding
Update the calculateDivision function to throw exceptions for invalid data, and ensure the main program handles these exceptions using try/catch blocks.
- If either
$numeratoror$denominatoris not numeric, throw anInvalidArgumentException. - If
$denominatoris zero, throw aDivisionByZeroError. - If both arguments are valid and the denominator is not zero, return the result of dividing
$numeratorby$denominator.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 4
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