-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_ExceptionFilters.cs
66 lines (56 loc) · 1.08 KB
/
05_ExceptionFilters.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
//
// All exmaples are taken from MS Roslyn Codeplex page
// https://www.codeplex.com/Download?ProjectName=roslyn&DownloadId=824694
//
namespace CSharp6Samples_ExceptionFilters
{
#region CSharp 5
public class ExceptionFiltersV5
{
public void Method ()
{
try
{
// do it
}
catch (Exception e)
{
if (MyFilterCondition (e))
{
// process exception
}
else
{
throw;
}
}
}
private bool MyFilterCondition (Exception e)
{
throw new NotImplementedException ();
}
}
#endregion
#region CSharp 6
public class ExceptionFiltersV6
{
public void Method ()
{
try
{
// do it
}
catch (Exception e) if (MyFilterCondition(e))
{
// only caught if MyFilterCondition is true
// if not filtered, stack is unharmed, exception keeps going
}
}
private bool MyFilterCondition (Exception e)
{
throw new NotImplementedException ();
}
}
#endregion
}