Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

=+2 Is the decision sustainable in the long run?

Answered: 1 week ago

Question

=+1 Is the decision fair to employees?

Answered: 1 week ago