Seksjon 2. Kapittel 4
single
Challenge: Add Exception Throwing to a Function
Sveip for å vise menyen
Oppgave
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
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 4
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår