Advertisement
jezzye13

Scenario 1-3 Exception

Aug 23rd, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. //Rextester.Program.Main is the entry point for your code. Don't change it.
  2. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Rextester
  10. {
  11.     public class Program
  12.     {
  13.         public static void Main(string[] args)
  14.         {
  15.             int x = 12;
  16.             int y = 0;
  17.            
  18.             Console.WriteLine(divide(x, y)); //calles diveide methode and print return value
  19.         }
  20.        
  21.         public static int divide(int x, int y) {
  22.             int result = -1; //default value
  23.             try { //try divideing
  24.                result = x / y;
  25.             } catch(Exception ex) { //call when error
  26.                 Console.WriteLine(ex.Message); //print error
  27.             }
  28.             return result; //return the value if -1 then error
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement