这是抛出异常的代码。
它在类GitHelper
中,由类GitProgressDialog
调用,它是bw_DoWork
方法。
public class GitHelper
{
....
if (!Run(commands[i]))
{
var e = new InvalidOperationException(Error);
e.Data["stepIndex"] = i;
throw e;
}
...
这是处理异常的代码:
public partial class GitProgressDialog : Form
{
...
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Cancelled == true)
{
}
else if (e.Error != null)
{
Success = false;
errorStepIndex = (int)e.Error.Data["stepIndex"];
SetError(e.Error.Message);
}
else
{
Success = true;
this.Close();
}
}
此行发生错误:
errorStepIndex = (int)e.Error.Data["stepIndex"];
System.NullReferenceException 你调用的对象是空的。
我猜数据设置不好?但为什么? 它适用于使用带有和不带调试器的Visual Studio。 对于客户端,它会激活主要的异常处理例程,该例程会记录并关闭应用程序。