Abschnitt 2. Kapitel 4
single
Challenge: Add Exception Throwing to a Function
Swipe um das Menü anzuzeigen
Aufgabe
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ösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 4
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen