Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Specific Exception Catching | Fundamentals of Exception Handling
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C# Exceptions and Error Handling Practice

bookChallenge: Specific Exception Catching

Task

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 resulting ArgumentNullException and throw a new ArgumentNullException with the message "Input string is null.".
  • If the input string is not a valid integer format, catch the resulting FormatException and throw a new FormatException with 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

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain this in simpler terms?

What are the main points I should remember?

Can you give me an example?

close

bookChallenge: Specific Exception Catching

Swipe to show menu

Task

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 resulting ArgumentNullException and throw a new ArgumentNullException with the message "Input string is null.".
  • If the input string is not a valid integer format, catch the resulting FormatException and throw a new FormatException with 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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 4
single

single

some-alt