Check and run the code to see how the test will pass
ยท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;
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX