如何在我的函数行中给出错误

时间:2014-02-11 16:29:42

标签: c# passwords

我有使用密码的函数,当我运行程序时,函数中的错误没有出现在我放在catch上的消息框中,如何在给出的行上给出错误错误?

public void CheckContent(string FileExe, string password)
{
 try
   {
       SevenZipExtractor szip = new SevenZipExtractor(FileExe, password); // <-- error if wrong password  
       foreach (ArchiveFileInfo file in szip.ArchiveFileData)
       {
          string NamaFile = file.FileName;
          string format = file.Extension;
          string[] row;
          row = new string[] { NamaFile, format };
          DGVDekripsi.Rows.Add(row);
       }
    }
    catch (IOException ex)
    {
        MessageBox.Show(this, ex.Message, "Proses Cek Isi File Exe", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

2 个答案:

答案 0 :(得分:4)

可能抛出异常的类型与IOException不同,你的catch块只会捕获IOException's。试试这个:

catch (Exception ex)
{
    MessageBox.Show(this, ex.Message, "Proses Cek Isi File Exe", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

如果你写ex.GetType(),你会看到异常的类型。然后,如果你希望你可以添加额外的cath块来捕获该异常,你可以正确处理它。

答案 1 :(得分:1)

你确定你的异常上升吗?或者它是一般的例外,你跟踪它了吗? 我认为你有一个正常的异常而不是IOException