Sección 2. Capítulo 2
single
Challenge: Implement a Custom Exception
Desliza para mostrar el menú
Tarea
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.
Solución
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 2. Capítulo 2
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla