Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Add Exception Throwing to a Function | Custom Exceptions and Advanced Handling
/
PHP Error Handling and Exceptions
Seção 2. Capítulo 4
single

single

bookChallenge: Add Exception Throwing to a Function

Deslize para mostrar o menu

Tarefa

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 $numerator or $denominator is not numeric, throw an InvalidArgumentException.
  • If $denominator is zero, throw a DivisionByZeroError.
  • If both arguments are valid and the denominator is not zero, return the result of dividing $numerator by $denominator.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 4
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

some-alt