Challenge: Specific Exception Catching
Taak
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.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 4
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Geweldig!
Completion tarief verbeterd naar 4.17
Challenge: Specific Exception Catching
Veeg om het menu te tonen
Taak
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.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 4
single