Challenge: Specific Exception Catching
Aufgabe
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ösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 1. Kapitel 4
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Großartig!
Completion Rate verbessert auf 4.17
Challenge: Specific Exception Catching
Swipe um das Menü anzuzeigen
Aufgabe
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ösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 1. Kapitel 4
single