I made some code to read a file and have a problem with try-catch block.
A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
Additional information: Could not find a part of the path 'D:...\WpfApplicationExample\bin\Debug\KeyWord\ROS\KeyWord_Booting_Time.json'.
I always meet this exception although already handled it.
my directory does definitely not exist, but I already handle it by catch
block, so why my app still crashes at this: StreamReader sr = new StreamReader(filePath)
.
Please take a look at the code below and tell me what is the problem?
try
{
StreamReader sr = new StreamReader(filePath);
jsonString = sr.ReadToEnd();
sr.Close();
}
catch (System.IO.DirectoryNotFoundException e)
{
Log.log(TAG, "getKeyWords", e.Message);
}
catch (System.IO.IOException e)
{
Log.log(TAG, "getKeyWords", e.Message);
}
catch (Exception e)
{
Log.log(TAG, "getKeyWords", e.Message);
}