Question: Edit the C# Code to solve the problem: The program parses the input into integer and catch possible problems with the value provided. Update this

Edit the C# Code to solve the problem: The program parses the input into integer and catch possible problems with the value provided. Update this code to use TryParse() method. Run it. Remove try-catch block completely. Run it

using System;

using static System.Console;

namespace HandlingExceptions

{

class Program

{

static void Main(string[] args)

{

WriteLine("Before parsing");

Write("What is your age? ");

string input = ReadLine();

try

{

int age = int.Parse(input);

WriteLine($"You are {age} years old.");

}

catch (OverflowException)

{

WriteLine("Your age is a valid number format but it is either too big or small.");

}

catch (FormatException)

{

WriteLine("The age you entered is not a valid number format.");

}

catch (Exception ex)

{

WriteLine($"{ex.GetType()} says {ex.Message}");

}

WriteLine("After parsing");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!