【发布时间】:2017-06-14 11:55:28
【问题描述】:
servicestack 的 ExceptionHandler(设置在 AppHostBase 的重写 Configure 方法中)在 lambda 中具有通用 Exception 类型的 'exception' 参数。
this.ExceptionHandler = (httpReq, httpResp, operationName, exception) =>
{
if(exception is ArgumentException)
{
// some code
}
}
在 lambda 内部,如果异常是 ArgumentException 类型,我希望添加一个特定条件。
有什么方法可以确定引发了哪种特定类型的异常?
使用 'is' 关键字检查类型不起作用,正如 link 给出的那样
仅供参考,为我们使用的 servicestack 实例实现了一个自定义 ServiceRunner。
【问题讨论】:
-
据我了解链接问题中的答案有效!?
-
是的。如果您的代码块未运行,则异常类型不是 ArguementException。尝试调试代码以查看它是什么类型的异常或尝试
exception.GetType().ToString()。 -
ServiceStack v4 中没有
ExceptionHandler,如果这是ServiceStack v3 you need to use the [servicestack-bsd] hash tag。 -
我再次检查了,但由于某种原因异常对象无法识别为
ExceptionHandler内的ArgumentException。最后,下面回答的解决方案有效。
标签: c# servicestack-bsd