- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在服务器上有以下代码:
if (actualRowCount > maxRows)
{
throw new DomainException("OverMaxRowLimitException",
new OverMaxRowLimitException(string.Format(MaxRowsMessage,
actualRowCount, maxRows)));
}
这将创建一个新的 DomainException
并设置了 InnerException
属性。我已验证这是在调试器中设置的。
自定义异常是这样定义的:
public class OverMaxRowLimitException : Exception
{
public OverMaxRowLimitException(string message)
{
this.Message = message;
}
public new string Message { get; set; }
}
这应该会向客户端返回一条合理的错误消息,以便可以告知用户行数过多。所以在加载完成处理程序中,我们希望:
if (result.HasError)
{
ShowError(result.Error.InnerException.Message);
}
不幸的是,InnerException
属性为 null
。因此,我们所要做的就是检查没有正确传输到客户端的外部异常消息的文本。
有人建议我需要:
<customErrors mode="Off" />
在网络配置文件中。我试过了,但没用。
也有人建议我需要:
[KnownType(typeof(OverMaxRowLimitException))]
关于数据契约(Contract)。现在,除非我把它放在错误的地方,否则这也不起作用。
我还尝试将 [Serializable]
添加到自定义异常并将其替换为通用 Exception
。这些都不起作用。
那么,为什么 InnerException
属性为 null。我错过了什么?
最佳答案
我想你应该使用
[FaultContract(typeof(OverMaxRowLimitException))]
为您的操作契约(Contract)。还有你的OverMaxRowLimitException
应该是可序列化的。
同样在用法中,我想抛出异常的正确方法是使用
throw new FaultException<OverMaxRowLimitException>(yourException);
关于c# - 为什么我的 InnerException 没有发送给客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14563690/
在我的代码中,我使用典型的 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
我是一名优秀的程序员,十分优秀!