Seksjon 2. Kapittel 2
single
Challenge: Implement a Custom Exception
Sveip for å vise menyen
Oppgave
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.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 2
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår