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

single

bookChallenge: Add Exception Throwing to a Function

Veeg om het menu te tonen

Taak

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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 4
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

some-alt