异常捕获的问题. [英] Problem with exception catch.

查看:62
本文介绍了异常捕获的问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



捕获从其他DLL库抛出的异常时出现问题.

这是我的代码,

Hi,

i have problem when catching my exception thrown from other DLL library.

here is my code,

throw new FaultException<ArgumentException>(new ArgumentException("my message", errorMessage), errorMessage);



我如何捕获此异常?





how can i catch this exception ?

something like

catch(System.ServiceModel.FaultException<ArgumentException>)

,但是它不起作用.

谢谢
-Amit.

but it won''t work.

thanks
-Amit.

推荐答案

使用
catch(FaultException<ArgumentException> exception) { /*...*/ }


通用语法始终有效;您只应该了解该类型始终是某些实例化类型FaultException<ArgumentException>.对于FaultException,这不是完全类型,这是泛型类型,未实例化.



它没有用"不是有效的问题报告.我只是给您提供了一种有效的方法来捕获特定类型的异常,该异常始终有效.如果您了解在何处使用任何有用的建议都可以奏效,而不是在不知道的catch块中捕捉到不应该命名的东西,因为您可能会遇到无尽的问题而又不真正了解什么.''继续.您应始终在调试器中的设置下运行代码,以获取所需的所有信息.

首先,您可以在每个线程的堆栈顶部上捕获 all 异常,例如,在每个处理程序上放置一个断点.当捕获到异常时,您应该检查其确切类型.重要的是,您需要查看Exception.Stack:这只是一个字符串.并且,如果调试信息在运行过程中可用,则if会向您显示引发/传播异常的所有文件名和行号,直到您停止该点为止.查看此信息,您可以解开所发生事件的全部历史记录.

—SA


General syntax always works; you only should understand that the type is always some instantiated type FaultException<ArgumentException>. As to FaultException, this is not exactly a type, this is a generic type, not instantiated.



"It did not work" is not a valid issue report. I just gave you a valid way to catch an exception of a certain type, which always work. Any useful advice can work if you understand where to use it, not that you catch something-which-should-not-be-named in a catch block who-knows-there, as you can experience endless problems without really understanding what''s going on. You should always run your code under debugger in the settings where you can get all the information you need.

To start with, you can catch all exceptions on top of the stack of each thread and, say, put a break point on every handler. When exception is caught, you should examine its exact type. Importantly, you need to look at Exception.Stack: this is just a string; and, if debug information was available during the run, if will show you all the file names and line numbers where the exception was thrown/propagated to the point you are stopped in. Looking this information, you can untie the whole history of what happened.

—SA


您必须将代码放在try {}中,并使用catch {}显示所需的消息.
You must place your code within try{} and show desired message withing catch{}.


这篇关于异常捕获的问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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