[英]Fetch thrown and swallowed Exception from CurrencyManager
The .NET Windows Forms CurrencyManager
swallows exceptions that are thrown while navigating (see "Bug in CurrencyManager.OnPositionChanged - eats exceptions" on MSDN Social ). .NET Windows窗体
CurrencyManager
吞噬了导航时引发的异常(请参阅MSDN Social上的“ Bug in CurrencyManager.OnPositionChanged-吃异常” )。
I, however, need to catch or fetch an exception that may be thrown in a CurrentChanged
event handler. 但是,我需要捕获或获取可能在
CurrentChanged
事件处理程序中引发的异常。 Is there a way to get it? 有办法吗? Subscribing
BindingComplete
and reading e.Exception
does not help. 订阅
BindingComplete
并阅读e.Exception
没有帮助。
bindingSource.MoveLast();
// exception isn't thrown up to here
private void bindingSource_CurrentChanged(object sender, EventArgs e)
{
// save old, throws exception
}
At the moment, the user gets no feedback when saving the old item fails. 目前,当保存旧项目失败时,用户没有任何反馈。 Therefore I need a way to get the exception.
因此,我需要一种获取异常的方法。
Cheers Matthias 欢呼马蒂亚斯
You could try to fetch it through: AppDomain.CurrentDomain.FirstChanceException
您可以尝试通过以下方式获取它:
AppDomain.CurrentDomain.FirstChanceException
Simple example code: 简单的示例代码:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.FirstChanceException += (s, e) => Console.WriteLine(String.Format("Exception thrown: {0}", e.Exception.GetType()));
try
{
ThrowException();
}
catch(InvalidProgramException)
{
// mjam mjam
}
Console.Read();
}
private static void ThrowException()
{
throw new InvalidProgramException("broken");
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.