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

single

bookChallenge: Implement a Custom Exception

Glissez pour afficher le menu

Tâche

Swipe to start coding

In this task, you will define a custom exception class and use it to handle invalid user input in a registration form scenario. This will help you practice creating your own exception types and using them to manage errors in a more meaningful way.

  • Define a custom exception class named InvalidRegistrationException that extends the built-in Exception class.
  • Implement the validateRegistration function so that it throws an InvalidRegistrationException if the username is empty.
  • Make the function throw an InvalidRegistrationException if the password is less than 6 characters long.
  • If both checks pass, the function should return a success message containing the username.

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 2
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