Skip to content

Commit

Permalink
Better handle IO exceptions when file held by another process
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchpaulus committed Aug 13, 2024
1 parent 22f707d commit cc7d05a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions excelchop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ static bool OptionMatches(string arg, IOption option)
Environment.ExitCode = 1;
Console.Error.Write(knownException.Message.EndWithSingleNewline());
}
catch (IOException ioException)
{
if (ioException.Message.Contains("The process cannot access the file") && ioException.Message.Contains("because it is being used by another process"))
{
Console.Error.Write(ioException.Message);
if (!ioException.Message.EndsWith('\n')) Console.Error.Write('\n');
Environment.ExitCode = 1;
return;
}

// Else rethrow.
throw;
}
catch
{
Environment.ExitCode = 1;
Expand Down

0 comments on commit cc7d05a

Please sign in to comment.