Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Handle Specific Exception Types | Understanding PHP Errors and Basic Exception Handling
PHP Error Handling and Exceptions
Section 1. Chapitre 6
single

single

Challenge: Handle Specific Exception Types

Glissez pour afficher le menu

Tâche

Glissez pour commencer à coder

Practice using multiple catch blocks to handle specific exception types in PHP. Build on your understanding of built-in exception classes by writing a function that throws different exceptions based on input.

  • Throw an InvalidArgumentException if the argument is not an integer.
  • Throw a RuntimeException if the argument is a negative integer.
  • Return the argument multiplied by 2 for valid input.

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 1. Chapitre 6
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