我们可以将异常附加到事件处理程序吗?我们可以在事件处理程序中添加异常吗?
这里是我的代码:
if (customer == null)
{
eventListener.HandleEvent(Severity.Informational, line.GetType().Name, String.Format("Could not find the customer corresponding to the taxId '{0}' Current Employment will not be imported.", new TaxId(line.TaxId).Masked));
return;
}
if (incomeType == null)
{
eventListener.HandleEvent(Severity.Warning, line.GetType().Name, String.Format("The income type of '{0}' in the amount of {1:c} is not a known type.", line.Type, line.Amount));
return;
}
可我把尝试catch块这些语句?因为我有很多错误消息是由事件处理程序处理的。所以不是写很多这个事件处理程序,我们可以通过只写一次来完成它?
你问你是否可以捕获异常并将其传递给'HandleEvent'方法? – JeremiahDotNet
'eventListener'的类型是什么? – jdphenix
它可能是有帮助的阅读此:http://msdn.microsoft.com/en-us/library/ms173160.aspx –