【发布时间】:2021-12-26 17:28:28
【问题描述】:
这可能是一个基本问题,但我无法通过搜索找到答案。我的代码导致异常写入 Visual Studio 中的“输出”->“调试”窗口。无论如何,我的try...catch 正在执行下一行代码。 NuGet 包除外。
这是否意味着 NuGet 包中发生异常并由 Nuget 包处理?如何进一步解决此问题?
private void HandleStorageWriteAvailable(IXDocument doc)
{
using IStorage storage = doc.OpenStorage(StorageName, AccessType_e.Write);
{
Debug.WriteLine("Attempting to write to storage.");
try
{
using (Stream str = storage.TryOpenStream(EntityStreamName, true))
{
if (str is not null)
{
try
{
string test = string.Concat(Enumerable.Repeat("*", 100000));
var xmlSer = new XmlSerializer(typeof(string));
xmlSer.Serialize(str, test);
}
catch (Exception ex)
{
Debug.WriteLine("Something bad happened when trying to write to the SW file.");
Debug.WriteLine(ex);
}
}
else
{
Debug.WriteLine($"Failed to open stream {EntityStreamName} to write to.");
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
}
异常发生在using (Stream str = storage.TryOpenStream(EntityStreamName, true)) 行,当异常发生时代码继续执行下一行而不是捕获。
如果该异常正在由其他东西处理,这是正常行为吗?我以前从未见过这种情况。
【问题讨论】:
-
> 这是否意味着 NuGet 包中发生异常并由 Nuget 包处理?大概是这个。如果原始代码不重新抛出异常,您将不会捕获它。要进行更多调查,您可以检查 NuGet 的源代码(如果可用)(它们通常是)