Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- Console.WriteLine("Enter a number:");
- int num = int.Parse(Console.ReadLine());
- if(num < 0)
- {
- throw new ArithmeticException();
- }
- Math.Sqrt(num);
- Console.WriteLine(Math.Sqrt(num));
- }
- catch(FormatException )
- {
- Console.WriteLine("Invalid number");
- }
- catch (OverflowException)
- {
- Console.WriteLine("Invalid number");
- }
- catch(ArithmeticException){
- Console.WriteLine("Negative number");
- }
- finally
- {
- Console.WriteLine("Goodbye!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement