Osio 2. Luku 2
single
Challenge: Implement a Custom Exception
Pyyhkäise näyttääksesi valikon
Tehtävä
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.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 2. Luku 2
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme