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