return 与文件读取异常
以下代码在文件不存在的时候,会报错,但无法被try..catch..捕获。
try
{
return await File.ReadAllTextAsync(tempCopy);
}
catch (Exception ex)
{
throw new IOException($"读取 MTP 文件失败: {mtpFullPath}", ex);
}
改成以下代码形式,工作正常:
try
{
var result = await File.ReadAllTextAsync(tempCopy);
return result;
}
catch (Exception ex)
{
throw new IOException($"读取 MTP 文件失败: {mtpFullPath}", ex);
}

浙公网安备 33010602011771号