Advertisement
vencinachev

Exceptions

Dec 1st, 2020
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void AgeAnalys(int age)
  12.         {
  13.             if (age < 0)
  14.             {
  15.                 throw new ArgumentException("Negative age...");
  16.             }
  17.             if (age <= 12)
  18.             {
  19.                 Console.WriteLine("Kid");
  20.             }
  21.             else if (age <= 19)
  22.             {
  23.                 Console.WriteLine("Teen");
  24.             }
  25.             else
  26.             {
  27.                 Console.WriteLine("Adult");
  28.             }
  29.         }
  30.  
  31.  
  32.         static void Main(string[] args)
  33.         {
  34.             int num = -15;
  35.             try
  36.             {
  37.                 AgeAnalys(num);
  38.             }
  39.             catch(ArgumentException)
  40.             {
  41.                 Console.WriteLine("Problem...");
  42.             }
  43.          
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement