-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathListing05.29.ThrowingAnException.cs
More file actions
40 lines (38 loc) · 1.14 KB
/
Listing05.29.ThrowingAnException.cs
File metadata and controls
40 lines (38 loc) · 1.14 KB
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
#pragma warning disable CS1058
#pragma warning disable CS0168 // Variable is declared but never used
#pragma warning disable CS0162 // Unreachable code detected
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_29;
public class ThrowingExceptions
{
// A previous catch clause already catches all exceptions
#region INCLUDE
public static void Main()
{
try
{
Console.WriteLine("Begin executing");
Console.WriteLine("Throw exception");
#region HIGHLIGHT
throw new Exception("Arbitrary exception");
// Catch 1
#endregion HIGHLIGHT
Console.WriteLine("End executing");
}
catch(FormatException exception)
{
Console.WriteLine(
"A FormatException was thrown");
}
// Catch 1
catch(Exception exception)
{
Console.WriteLine(
$"Unexpected error: { exception.Message }");
// Jump to Post Catch
}
// Post Catch
Console.WriteLine(
"Shutting down...");
}
#endregion INCLUDE
}