我知道如何搭上all未处理的异常的在一个给定的线程,但不知道是否有一种方法可以捕捉所有未处理的异常抛出一个给定的类,而不是在一个try catch块包裹每个调用。
I know how to catch all unhandled exceptions in a given thread, but wondering if there is a way to catch all unhandled exceptions thrown by a given class instead of wrapping each of the calls in a try catch block.
在情况下,有没有办法这样做的(很可能是这种情况),你将如何达到同样的效果?
In case there's no way of doing this (likely to be the case) how would you achieve the same effect?
只给一点背景下,我使用的是从服务的数据契约(WCF)解耦应用程序的其它部分的自定义codeD服务代理。基本上,我需要赶上故障,这样我可以提取特定领域(内说明等),把它们打包成一个自定义异常,再次抛出了。
Just to give a bit of context, I am using a custom coded service proxy that decouples the rest of the app from the service data contract (WCF). I basically need to catch the faults so that I can extract specific fields (inner descriptions etc.), package them up into an custom exception and throw it again.
任何帮助AP preciated。
Any help appreciated.
如果它是关于WCF的例外,我会建议堵漏专用行为纳入WCF管道。我写了一个详细的例子here
If it is about WCF exceptions, I would recommend plugging a dedicated behavior into the WCF pipeline. I have written a detailed example here
它基于两个接口IErrorHandler和IServiceBehavior接口,它也可用作一个属性并在基于文件的配置。
It is based on two interfaces IErrorHandler and IServiceBehavior, it is also usable as an attribute and in file-based configurations.