forked from 47-studio-org/PostSharp.Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
47 lines (38 loc) · 1.09 KB
/
Program.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
using PostSharp.Samples.ExceptionHandling;
using System;
// Add the AddContextOnException aspect to all methods in the assembly.
[assembly: AddContextOnException]
namespace PostSharp.Samples.ExceptionHandling
{
internal class Program
{
private static void Main(string[] args)
{
MainCore();
// Proofs that MainCore succeeded despite Finbonacci throwing an exception.
Console.WriteLine("The program returns successfully.");
}
[ReportAndSwallowException]
private static void MainCore()
{
// The Fibonacci method will fail with an exception, but the [ReportAndSwallowException] aspect
// will swallow the exception and the MainCore method will succeed.
Fibonacci(5);
}
public static int Fibonacci(int n)
{
if (n < 0)
{
throw new ArgumentOutOfRangeException();
}
if (n == 0)
{
return 0;
}
// The next lines are intentionally commented out to cause an exception:
// if (n == 1)
// return 1;
return Fibonacci(n - 1) + Fibonacci(n - 2);
}
}
}