【发布时间】:2023-04-02 11:43:01
【问题描述】:
我有这两种方法,而且我确信 DoSomethingAsync 返回一个 FormatException。但是它总是在最后一个 catch “Exception”中被捕获
为什么 CallSomethingAsync 永远不会捕获 FormatException?
public Task DoSomethingAsync()
{
//Do something that throws a FormatException
return Task.FromResult(0);
}
public virtual string CallSomethingAsync()
{
try
{
this.DoSomethingAsync().Wait();
return “Ok”;
}
catch (FormatException)
{
return “FormatException”;
}
catch (Exception)
{
return “GeneralException”;
}
}
【问题讨论】:
标签: c# asp.net-mvc exception-handling task