Challenge: Specific Exception Catching
Tarefa
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.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 4
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Suggested prompts:
Can you explain this in simpler terms?
What are the main points I should remember?
Can you give me an example?
Incrível!
Completion taxa melhorada para 4.17
Challenge: Specific Exception Catching
Deslize para mostrar o menu
Tarefa
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.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 4
single