如何访问 InnerException 的 InnerExceptions 属性?
How do I access the InnerExceptions property of an InnerException?
在我的代码中,我使用典型的 try..catch 抛出并捕获了异常。异常中的消息是 An error occured while executing the query. Please check the stack trace for more detail.
还有一个 InnerException,消息为 ValidationException was thrown.
There is no other InnerException。但是,当我通过 Visual Studio 2015 查看异常时,我可以展开异常,转到 InnerException 并展开它,然后我看到:
InnerException: Nothing
InnerExceptions: Count=1
然后我可以展开 InnerExceptions 分支并查看我假设的 AggregateException,在本例中显示
(0): {"Error Parsing query"}
Raw View:
然后我可以展开 (0) 组来查看像 "Detail" 这样的属性,它给出了完整而详细的错误消息以及 "ErrorCode" 和许多其他属性。
当我尝试通过 ex.InnerException.InnerExceptions 通过代码引用 "InnerExceptions" 时,我不能,因为 'InnerExceptions' 不是'Exception'.
它如何在 Visual Studio IDE 中可见但无法通过代码获得?
我正在编写使用 IppDotNetSdkForQuickBooksApiV3 NuGet 包的代码。我提到这一点是因为我不确定这是否是以某种方式从 Intuit 的 API 添加的。我以前从未遇到过 InnerExceptions 组。
明确一点:迭代 InnerException 属性 不会 return 在上述 "Detail" 中发现相同的错误。
Exception
class 没有名为 InnerExceptions 的成员,但是它是 AggregateException 的基础 class,它有。 Visual Studio 的调试器将找出每个对象的类型,因此能够显示每个 属性 它们拥有的。
但是异常 class 的 InnerException 成员不是 AggregateException 类型,只是一个通用异常。也就是说,Visual Studio 无法确定您的 InnerException 是否实际上是类型的 AggregateException。要解决这个问题,你需要施法。
我不太熟悉 vb.net 语法,在 C# 领域它会像这样:
((AggregateException)ex.InnerException).InnerExceptions
或者您可以像这样安全地尝试投射:
if (ex.InnerException.GetType() == typeof(AggregateException))
{
var listOfInnerExceptions = ((AggregateException)ex.InnerException).InnerExceptions;
}
据我所知,VB.net 中有一个 DirectCast(obj, type)
方法可用于此目的,但我对此可能是错误的。
在我的代码中,我使用典型的 try..catch 抛出并捕获了异常。异常中的消息是 An error occured while executing the query. Please check the stack trace for more detail.
还有一个 InnerException,消息为 ValidationException was thrown.
There is no other InnerException。但是,当我通过 Visual Studio 2015 查看异常时,我可以展开异常,转到 InnerException 并展开它,然后我看到:
InnerException: Nothing
InnerExceptions: Count=1
然后我可以展开 InnerExceptions 分支并查看我假设的 AggregateException,在本例中显示
(0): {"Error Parsing query"}
Raw View:
然后我可以展开 (0) 组来查看像 "Detail" 这样的属性,它给出了完整而详细的错误消息以及 "ErrorCode" 和许多其他属性。
当我尝试通过 ex.InnerException.InnerExceptions 通过代码引用 "InnerExceptions" 时,我不能,因为 'InnerExceptions' 不是'Exception'.
它如何在 Visual Studio IDE 中可见但无法通过代码获得?
我正在编写使用 IppDotNetSdkForQuickBooksApiV3 NuGet 包的代码。我提到这一点是因为我不确定这是否是以某种方式从 Intuit 的 API 添加的。我以前从未遇到过 InnerExceptions 组。
明确一点:迭代 InnerException 属性 不会 return 在上述 "Detail" 中发现相同的错误。
Exception
class 没有名为 InnerExceptions 的成员,但是它是 AggregateException 的基础 class,它有。 Visual Studio 的调试器将找出每个对象的类型,因此能够显示每个 属性 它们拥有的。
但是异常 class 的 InnerException 成员不是 AggregateException 类型,只是一个通用异常。也就是说,Visual Studio 无法确定您的 InnerException 是否实际上是类型的 AggregateException。要解决这个问题,你需要施法。
我不太熟悉 vb.net 语法,在 C# 领域它会像这样:
((AggregateException)ex.InnerException).InnerExceptions
或者您可以像这样安全地尝试投射:
if (ex.InnerException.GetType() == typeof(AggregateException))
{
var listOfInnerExceptions = ((AggregateException)ex.InnerException).InnerExceptions;
}
据我所知,VB.net 中有一个 DirectCast(obj, type)
方法可用于此目的,但我对此可能是错误的。