[英]Fetch thrown and swallowed Exception from CurrencyManager
.NET Windows窗体CurrencyManager
吞噬了导航时引发的异常(请参阅MSDN Social上的“ Bug in CurrencyManager.OnPositionChanged-吃异常” )。
但是,我需要捕获或获取可能在CurrentChanged
事件处理程序中引发的异常。 有办法吗? 订阅BindingComplete
并阅读e.Exception
没有帮助。
bindingSource.MoveLast();
// exception isn't thrown up to here
private void bindingSource_CurrentChanged(object sender, EventArgs e)
{
// save old, throws exception
}
目前,当保存旧项目失败时,用户没有任何反馈。 因此,我需要一种获取异常的方法。
欢呼马蒂亚斯
您可以尝试通过以下方式获取它: AppDomain.CurrentDomain.FirstChanceException
简单的示例代码:
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.