.net 从CurrencyManager获取引发并吞没的异常
.NET Windows窗体.net 从CurrencyManager获取引发并吞没的异常,.net,winforms,exception,data-binding,currencymanager,.net,Winforms,Exception,Data Binding,Currencymanager,.NET Windows窗体CurrencyManager接受导航时引发的异常(请参阅) 一、 但是,需要捕获或获取可能在CurrentChanged事件处理程序中引发的异常。有办法得到它吗?订阅BindingComplete和阅读e.Exception没有帮助 bindingSource.MoveLast(); // exception isn't thrown up to here private void bindingSource_CurrentChanged(object sende
CurrencyManager
接受导航时引发的异常(请参阅)
一、 但是,需要捕获或获取可能在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您可以尝试通过以下方式获取它:
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");
}
}
}
谢谢,这就行了。我将异常包装在
WrappedException
类中,以区分我想要的异常和域中抛出的其他异常(is
操作符)。