尝试,赶上找不到文件 [英] try, catch to get file not found

查看:48
本文介绍了尝试,赶上找不到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我没有显示该消息框?我只能在输出中看到错误"mscorlib.dll中发生了类型为"System.IO.FileNotFoundException"的第一次机会异常".

Why I am not shown the message box?, I can just see the error in the output "A first chance exception of type ''System.IO.FileNotFoundException'' occurred in mscorlib.dll"

private void btnLoadWeigths_Click(object sender, EventArgs e)
      {
          try
          {
              wieghtL = loadNN("Weights.data");
              loadWeigths = true;
              checkWeight();
          }
          catch //(System.IO.FileNotFoundException)
          {
              MessageBox.Show("Wieights.data Not Found");
          }
      }

推荐答案

您可以使用如下所示的内容:

you can use something like below :

if (File.Exists(YourFilePath))
{
       wieghtL = loadNN("Weights.data");
       loadWeigths = true;
       checkWeight();
}
else
{
     MessageBox.Show("Wieights.data Not Found");
}


您确定loadNN尚未为此目的拥有自己的try/catch吗?在这种情况下,您可能会在调试时看到异常,具体取决于Visual Studio中的异常配置.

如果您拥有完整的源代码,则在调试器中应该很容易看到假定Visual Studio配置为在异常(这种类型)上中断.
Are you sure that loadNN does not already have its own try/catch for that purpose? In that case, you might see the exception while debugging depending on your exception configuration Inside Visual Studio.

If you have the whole sopurce code, it should be fairly easy to see in the debugger assume that Visual Studio is configured to break on exceptions (of this type).


这篇关于尝试,赶上找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆