-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test2.cs
56 lines (43 loc) · 1002 Bytes
/
Test2.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
/*
Instructions
------------
This program relies on an call to an external dependency that sometimes fails.
Handle the exception and ouput the appropriate response.
*/
using System;
public class Program
{
public void Main()
{
Result result = GetResult();
Console.WriteLine(result.Successful ? "It worked!!" : "Oops, something went wrong...");
}
private Result GetResult()
{
Result result = new Result();
try{
ExternalDependency service = new ExternalDependency();
service.DoWork();
result.Successful = true;
}catch(IndexOutOfRangeException e)
{
Console.WriteLine("Error occured: {0}", e.Message);
result.Successful = false;
}
return result;
}
}
public class Result
{
public bool Successful { get; set; }
}
// Please do not change the following class.
// Assume that it is an external dependency that is out of your control.
sealed class ExternalDependency
{
public void DoWork()
{
int[] array = new int[1];
array[new Random().Next(2)] = 0;
}
}