-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExceptionHandlingTests.cs
41 lines (38 loc) · 1.31 KB
/
ExceptionHandlingTests.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyExampleLibrary
{
class ExceptionHandlingTests
{
public static void Initialize()
{
Console.Clear();
Console.SetCursorPosition(0, 0);
try
{
Console.Write("Enter a number: ");
int num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter another number: ");
int num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(num1 / num2);
}
catch (DivideByZeroException e) //If you declare an Exception and it respective name, you will display all kind of exceptions that could happen
//otherwise if you declare an specific exception you will be able only to catch and handle that issue, otherwise the program will crash.
//Specific exception example: (DivideByZeroException e)
{
Console.WriteLine("[MATH-ERROR] " + e.Message);
}
catch (FormatException e)
{
Console.WriteLine("[FORMAT-ERROR] " + e.Message);
}
finally
{
}
Console.ReadLine();
}
}
}