Challenge: Specific Exception Catching
Oppgave
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.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 4
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Suggested prompts:
Can you explain this in simpler terms?
What are the main points I should remember?
Can you give me an example?
Fantastisk!
Completion rate forbedret til 4.17
Challenge: Specific Exception Catching
Sveip for å vise menyen
Oppgave
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.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 4
single