Skip to content

Commit ebbf118

Browse files
committed
File.Exists instead of try-catch for HitsFile creation/update validation
1 parent b51554d commit ebbf118

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/coverlet.core/Instrumentation/ModuleTrackerTemplate.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ public static void UnloadModule(object sender, EventArgs e)
8282
if (!createdNew)
8383
mutex.WaitOne();
8484

85-
bool failedToCreateNewHitsFile = false;
86-
try
85+
if (!File.Exists(HitsFilePath))
8786
{
8887
using (var fs = new FileStream(HitsFilePath, FileMode.CreateNew))
8988
using (var bw = new BinaryWriter(fs))
@@ -95,12 +94,7 @@ public static void UnloadModule(object sender, EventArgs e)
9594
}
9695
}
9796
}
98-
catch
99-
{
100-
failedToCreateNewHitsFile = true;
101-
}
102-
103-
if (failedToCreateNewHitsFile)
97+
else
10498
{
10599
// Update the number of hits by adding value on disk with the ones on memory.
106100
// This path should be triggered only in the case of multiple AppDomain unloads.

0 commit comments

Comments
 (0)