有没有办法赶上抛出一个给定类的所有未处理的异常? [英] Is there a way to catch all unhandled exceptions thrown by a given class?

查看:177
本文介绍了有没有办法赶上抛出一个给定类的所有未处理的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何搭上<一个href="http://stackoverflow.com/questions/295731/easy-way-to-catch-all-unhandled-exceptions-in-c-net">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管道。我写了一个详细的例子<一href="http://johannblais.blogspot.com/2009/02/handling-exceptions-right-way-in-wcf.html">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.

这篇关于有没有办法赶上抛出一个给定类的所有未处理的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆