CSharp examples for Custom Type:Exception
Handling Exceptions
using System;/*from w ww. j ava 2 s . c om*/ using static System.Console; class Program { static void Main(string[] args) { Write("What is your age? "); string input = Console.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}"); } } }