Skip to content

Throw from finally (ARCH404)

Key dotnet.exception.throw-from-finally · Severity error · Category exception

Throwing exceptions from finally blocks masks the original exception from the try or catch block, hiding the real cause of failure.

try
{
_repository.Save(order);
}
finally
{
if (!_connection.IsClosed)
throw new InvalidOperationException("Connection still open");
}
try
{
_repository.Save(order);
}
finally
{
if (!_connection.IsClosed)
_logger.LogWarning("Connection still open");
}

Log the condition instead of throwing in finally, or restructure the cleanup logic. If needed, suppress the rule per project/workspace via except/ignore.