Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Add Exception Throwing to a Function | Custom Exceptions and Advanced Handling
PHP Error Handling and Exceptions
Sección 2. Capítulo 4
single

single

bookChallenge: Add Exception Throwing to a Function

Desliza para mostrar el menú

Tarea

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.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 4
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt