catch security exception and access denied exception while trying to read a file (#7140)

This commit is contained in:
Alekhya
2020-10-07 12:56:57 -07:00
committed by GitHub
parent 2bd6c5c664
commit 0c0aec0f2a

View File

@@ -2,7 +2,9 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using System.Security;
using Wox.Infrastructure.Logger;
namespace Wox.Infrastructure.FileSystemHelper
@@ -19,9 +21,9 @@ namespace Wox.Infrastructure.FileSystemHelper
{
return File.ReadAllLines(path);
}
catch (IOException ex)
catch (System.Exception ex) when (ex is SecurityException || ex is UnauthorizedAccessException || ex is IOException)
{
Log.Info($"File {path} is being accessed by another process| {ex.Message}", GetType());
Log.Info($"Unable to read File: {path}| {ex.Message}", GetType());
return new string[] { string.Empty };
}