Advertisement
Martichka

Exception Handling/ Task - 1 IntegerSqrtRoot

Jan 27th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2. class IntegerSquareRoot
  3. {
  4.     static void Main()
  5.     {
  6.         string input = Console.ReadLine();
  7.         try
  8.         {
  9.             int num = int.Parse(input);
  10.             Console.WriteLine(Math.Sqrt(num));
  11.         }
  12.         catch (FormatException)
  13.         {
  14.             Console.WriteLine("Invalid number.");
  15.         }
  16.         catch (ArgumentException)
  17.         {
  18.             Console.WriteLine("Invalid number.");
  19.         }
  20.         catch (OverflowException)
  21.         {
  22.             Console.WriteLine("Invalid number.");
  23.         }
  24.         finally
  25.         {
  26.             Console.WriteLine("Good bye.");
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement