Секція 2. Розділ 4
single
Challenge: Add Exception Throwing to a Function
Свайпніть щоб показати меню
Завдання
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.
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 2. Розділ 4
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат