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

single

bookChallenge: Implement a Custom Exception

Swipe to show menu

Task

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 desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt