我有以下函数,在我最近更新 Visual Studio 2022 编译器 (17.11.4) 之前,该函数一直有效。我从编译器收到的错误是:not all code paths return a value
。但哪条路径未被覆盖?一个是return GetAllDatesWithoutLock();
,另一个是重新抛出ExceptionDispatchInfo.Throw(ex);
?此代码在更新之前运行正常。
public ScheduleDateTimeResponse GetAllDates()
{
log.Info("GetAllDates before locking");
semaphoreObject.Wait();
try
{
return GetAllDatesWithoutLock();
}
catch (Exception ex)
{
Console.WriteLine(Thread.CurrentThread.Name + "Error occurred.");
log.Error(Thread.CurrentThread.Name + "Error occurred in GetAllDates:", ex);
ExceptionDispatchInfo.Throw(ex);
}
finally
{
semaphoreObject.Release();
log.Info("GetAllDates after locking");
}
}