- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的代码中,我使用典型的 try..catch 抛出并捕获了异常。异常中的消息是 执行查询时发生错误。请检查堆栈跟踪以获取更多详细信息。
还有一个带有消息 ValidationException was thrown.
的 InnerException。没有其他 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 属性不会返回在上述“详细信息”中发现的相同错误。
最佳答案
Exception
类没有名为 InnerExceptions 的成员,但它是 AggregateException 的基类其中有。 Visual Studio 的调试器将找出每个对象的类型,因此能够显示它们拥有的每个属性。
然而,Exception 类的 InnerException 成员不是 AggregateException 类型,只是一个通用的 Exception。也就是说,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)
方法可用于此目的,但我对此可能是错误的。
关于c# - 如何访问 InnerException 的 InnerExceptions 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34203058/
在我的代码中,我使用典型的 try..catch 抛出并捕获了异常。异常中的消息是 执行查询时发生错误。请检查堆栈跟踪以获取更多详细信息。还有一个带有消息 ValidationException wa
何时检查 Exception 类及其派生类的 InnerException 属性?微软的“异常最佳实践”没有提供任何关于何时检查内部异常的建议。我应该只在异常被重新抛出并在我的代码中捕获时才这样做吗?
当我在该对象的构造函数中时,如何设置 Exception 对象的 InnerException 属性?这归结为查找和设置没有 setter 的属性的支持字段。 顺便说一句:我看过这个evain.net
在我多年的编程中,我从未见过这种情况发生,不得不问问是否有其他人知道这是为什么...... Excel.Worksheet worksheet; Excel.S
Regarding the duplicated. I can access the Message property but not the Detail property even when I
我有如下代码来捕获使用 TaskFactory 和 Task.Run 创建的任务抛出的异常。如果我使用 TaskFactory,则无需使用 Task.WaitAll 方法即可检查 Continued
我在服务器上有以下代码: if (actualRowCount > maxRows) { throw new DomainException("OverMaxRowLimitException
有什么方法可以编写 LINQ 样式的“速记”代码来遍历抛出异常的所有级别的 InnerException 吗?我更愿意就地编写它,而不是调用扩展函数(如下所示)或继承 Exception 类。 sta
显示我的完整 InnerException 的正确方法是什么。 我发现我的一些 InnerExceptions 有另一个 InnerException 并且这很深入。 InnerException.T
如何使用 Log4NET 记录内部异常? 这是我当前的转换模式: 最佳答案 控制台和文件附加器自动打印异常。异常:消息、堆栈跟踪和所有内部异常(再次使用堆栈跟踪)都记录在单独的行上,并且不遵循转换模
基本上,我的问题简短而有趣:以下是一个坏主意吗(封装并重新抛出 ex.InnerException 而不是 ex) (有一个类似的问题 here,但不完全...我想重新封装 InnerExceptio
我正在通过反射调用一个可能导致异常的方法。如何在没有包装器反射的情况下将异常传递给我的调用者? 我正在重新抛出 InnerException,但这会破坏堆栈跟踪。 示例代码: public void
我目前正在记录错误并希望获得尽可能多的描述性细节。我知道我可以捕获许多不同类型的异常,但 Exception.Message 之间有什么区别?和 Exception.InnerException.Me
我有一个带有操作契约(Contract)的 WCF 服务 void AddQuery(IQuery Query); 我的IQuery是这样的 public interface IQuery {
对于我正在开发的一个简单的控制台应用程序,我想实现一个非常基本的异常处理(只是打印异常消息并终止程序)。我要实现的逻辑是:如果异常有内部异常,则打印内部异常;否则打印自己的异常消息。 我尝试使用新的
我正在尝试使用 Entity Framework 将一个实体插入到我的数据库中。见下文: private void InsertarIntoDataBase() { Juego game =
使用 Visual Studio 2012 Express,当从外部代码框架引发 System.TypeInitializationException 时,如何检查 InnerException。调试
我们的(相当大的)代码库有一些这样的结构: try { DoSomething(); } catch (Exception e) { CleanUp(); throw new
简介 当用户在 NLog 配置中创建错误(如无效的 XML)时,我们 (NLog) 会抛出一个 NLogConfigurationException。异常包含错误的描述。 但有时如果对 NLog 的第
我一直在查看我们的一个应用程序中的一些代码,如下所示: catch (AggregateException ae) { this._logger.Log(ae.Flatten().InnerE
我是一名优秀的程序员,十分优秀!