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

bookChallenge: Specific Exception Catching

Tâche

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

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 4
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookChallenge: Specific Exception Catching

Glissez pour afficher le menu

Tâche

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 desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 4
single

single

some-alt