代码之家  ›  专栏  ›  技术社区  ›  user1725266

用户代码未处理DirectoryNotFoundException

  •  0
  • user1725266  · 技术社区  · 12 年前

    我对try-catch和异常处理非常熟悉。我希望我的程序在找不到目录或文件时捕获异常。 每当我运行程序时,我都会收到错误“DirectoryNotFoundException未被用户代码处理-something.dll中发生了类型为“System.IO.DirectyNotFoundException”的异常,但未在用户代码中处理”

    我可以看到Visual Studio在DirectoryNotFoundDirection上中断了,有什么想法吗?

    try {
        LiveDownloadOperation operation = await connectClient.CreateBackgroundDownloadAsync(filePath);
        var result = await operation.StartAsync();
    }
    catch (FileNotFoundException filEx) {
       Debug.WriteLine(filEx.Message);
       throw filEx;
    }
    catch (DirectoryNotFoundException dirEx) {
       Debug.WriteLine(dirEx.Message);
       throw;
    }
    catch (IOException ioEx) {
        Debug.WriteLine(ioEx.Message);
        throw ioEx;
    }
    catch (Exception ex) {
        Debug.WriteLine(ex.Message);
        throw;
    }
    

    EDIT:在try中显示代码

    1 回复  |  直到 12 年前
        1
  •  2
  •   Gary Walker    12 年前

    由于该目录不存在(或存在权限问题等),因此会引发DirectoryNotFoundException。

    您处理了该异常,然后重新评估——因为,调试器正确地表示未处理该异常。