Sectie 2. Hoofdstuk 2
single
Challenge: Implement a Custom Exception
Veeg om het menu te tonen
Taak
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
InvalidRegistrationExceptionthat extends the built-inExceptionclass. - Implement the
validateRegistrationfunction so that it throws anInvalidRegistrationExceptionif the username is empty. - Make the function throw an
InvalidRegistrationExceptionif the password is less than 6 characters long. - If both checks pass, the function should return a success message containing the username.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 2
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.