.NET Windows窗体CurrencyManager
吞下导航时抛出的异常(请参阅"Bug in CurrencyManager.OnPositionChanged - eats exceptions" on MSDN Social)。
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
}
目前,当保存旧项目失败时,用户不会收到任何反馈。因此,我需要一种方法来获得异常。
干杯 的Matthias
答案 0 :(得分:1)
您可以尝试通过以下方式获取它: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");
}
}
}