-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path38-TryCatchFinally.cs
46 lines (42 loc) · 1.1 KB
/
38-TryCatchFinally.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HackerRank
{
//NOTE: try catch and finally run in sequence, if there is throw in catch then it wont run further and exit the program with
// exception message.
internal class TryCatchFinally_Result
{
int result;
public TryCatchFinally_Result()
{
result = 0;
}
public void Division(int num1, int num2)
{
try
{
result = num1 / num2;
}
catch (DivideByZeroException e)
{
//throw e;
Console.WriteLine("Exception caught: {0}", e);
}
finally
{
Console.WriteLine($"result executes when no throw e :{result}");
}
}
}
internal class TryCatchFinally_Solution
{
public static void Input()
{
TryCatchFinally_Result objTry = new TryCatchFinally_Result();
objTry.Division(3, 0);
}
}
}