[英]3rd party library catches my exceptions
I've got a 3rd party API library which contains a set of request functions. 我有一个第三方API库,其中包含一组请求函数。 Responses are got by subscribing to events. 订阅事件即可获得响应。
If and exception is thrown in my event handler - the 3rd party library catches it and does nothing after. 如果在我的事件处理程序中引发了异常,则第三方库将其捕获,之后不执行任何操作。 This doesn't let me know if I have any problems with my code. 这不会让我知道我的代码是否有任何问题。
Is there any way to catch my exceptions before the 3rd party library does? 在第3方库之前,有什么方法可以捕获我的异常吗?
I thought on writing wrappers for event handlers but it doesn't seem to be a good solution. 我曾考虑为事件处理程序编写包装器,但这似乎不是一个好的解决方案。
Subscribing to AppDomain.FirstChanceException
doesn't give any effect. 订阅AppDomain.FirstChanceException
不会产生任何效果。
Is there any way to catch my exceptions before the 3rd party library does? 在第3方库之前,有什么方法可以捕获我的异常吗?
HandlerFunction()
{
try
{
/* place handler body here */
}
catch(Exception e)
{
/* you may store/log the exception object here */
}
}
ThirdPartyObject.Event += HandlerFunction;
In the catch clause, you may also add your exception object to a global error log so that you can keep track of it. 在catch子句中,您还可以将异常对象添加到全局错误日志中,以便您可以跟踪它。
Also you may place a breakpoint in the exception clause to debug your errors. 另外,您可以在exception子句中放置一个断点以调试错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.