Advertisement
RockField64

try-catch for Inventory

Oct 26th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1.  public string Product_Name(string name)
  2.         {
  3.             try
  4.             {
  5.                 if (!Regex.IsMatch(name, @"^[a-zA-Z]+$"))
  6.                     return name;
  7.             }
  8.            
  9.                 catch (StringFormatException sfe)
  10.                 {
  11.                 Console.WriteLine("String Format Exception " + sfe.Message);
  12.                 }
  13.                
  14.         }
  15.         public int Quantity(string qty)
  16.         {
  17.             try
  18.             {
  19.                 if (!Regex.IsMatch(qty, @"^[0-9]"))
  20.                     //Exception here
  21.                     return Convert.ToInt32(qty);
  22.             }
  23.             catch (NumberFormatException nfe)
  24.             {
  25.                 Console.WriteLine("Number Format Exception " + nfe.Message);
  26.             }
  27.            
  28.         }
  29.         public double SellingPrice(string price)
  30.         {
  31.             try
  32.             {
  33.                 if (!Regex.IsMatch(price.ToString(), @"^(\d*\.)?\d+$"))
  34.                     //Exception here
  35.                     return Convert.ToDouble(price);
  36.             }
  37.            catch (CurrencyFormatException cfe)
  38.             {
  39.                 Console.WriteLine("Currency Format Exception " + cfe.Message);
  40.             }
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement