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

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

问题描述

我知道如何抓住所有未处理的例外情况,但是想知道是否有一种方法来捕获给定类抛出的所有未处理的异常,而不是将每个调用包装在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)分离。我基本上需要抓住这些错误,以便我可以提取特定的字段(内部描述等),将它们打包成一个自定义异常并重新抛出。

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.

任何帮助赞赏。

推荐答案

如果是关于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.

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

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