Check and run the code to see how the test will pass
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
using System;
using System.IO;
namespace ExceptionHandling
{
public class FileHelper
{
public static string ReadFileContents(string path)
{
var data = "";
try
{
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (var file = new StreamReader(stream))
{
data = file.ReadToEnd();
}
}
}
catch (FileNotFoundException ex)
{
//Log the exception message from ex object
//Return a graceful message back to the caller
data = "Couldn't find file. Make sure it exists in the specific path";
}
catch (IOException ex)
{
//Log the exception message from ex object
//Return a graceful message back to the caller
data = "Unable to read from file";
}
catch (Exception ex)
{
//Log the exception message from ex object
//Return a graceful message back to the caller
data = "Something went wrong";
}
return data;
}
}
}
Enter to Rename, Shift+Enter to Preview
1
using Microsoft.VisualStudio.TestTools.UnitTesting;
Enter to Rename, Shift+Enter to Preview