Challenge: Specific Exception Catching
Tâche
Swipe to start coding
Implement a method that parses a string to an integer, handling both null and format errors with specific catch blocks.
- If the input string is
null, catch the resultingArgumentNullExceptionand throw a newArgumentNullExceptionwith the message"Input string is null.". - If the input string is not a valid integer format, catch the resulting
FormatExceptionand throw a newFormatExceptionwith the message"Input string is not in a correct format to parse to int.". - If the input string is a valid integer, return its parsed value.
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 1. Chapitre 4
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Génial!
Completion taux amélioré à 4.17
Challenge: Specific Exception Catching
Glissez pour afficher le menu
Tâche
Swipe to start coding
Implement a method that parses a string to an integer, handling both null and format errors with specific catch blocks.
- If the input string is
null, catch the resultingArgumentNullExceptionand throw a newArgumentNullExceptionwith the message"Input string is null.". - If the input string is not a valid integer format, catch the resulting
FormatExceptionand throw a newFormatExceptionwith the message"Input string is not in a correct format to parse to int.". - If the input string is a valid integer, return its parsed value.
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 1. Chapitre 4
single