Using throw statement-
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace throw_throwex { class Program { static void Main(string[] args) { //difference between throw and throw ex in c# try { int x = calc(5, 0); Console.WriteLine(x); Console.ReadLine(); } catch (Exception) { throw; } } public static int calc(int a, int b) { return a / b; } } }
Output:Using throw ex statement-
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace throw_throwex { class Program { static void Main(string[] args) { //difference between throw and throw ex in c# try { int x = calc(5, 0); Console.WriteLine(x); Console.ReadLine(); } catch (Exception ex) { throw ex; } } public static int calc(int a, int b) { return a / b; } } }
0 comments:
Post a Comment