Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Add Exception Throwing to a Function | Custom Exceptions and Advanced Handling
PHP Error Handling and Exceptions
Section 2. Chapitre 4
single

single

Challenge: Add Exception Throwing to a Function

Glissez pour afficher le menu

Tâche

Glissez pour commencer à coder

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.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 4
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt