为什么我检测到无法访问的代码?

use*_*612 0 c#

代码:

catch(Exception ex)
{
  if (ex is WebException)
  {
    wccfg.failedUrls++; //  i think you forgot this
    return csFiles;
  }
  else
  {
    throw new Exception("");
    wccfg.failedUrls++;
    return csFiles;
  }
}
Run Code Online (Sandbox Code Playgroud)

在第二个wccfg(另一个类)上,我看到绿线表示检测到无法访问的代码.我应该将此行移到抛出新的异常行吗?

Mik*_*sen 8

因为一旦你:

throw new Exception("");
Run Code Online (Sandbox Code Playgroud)

在该点之后没有其他代码将被执行.

是的 你需要一个return或一个throw,你不能两者兼得.

也没有理由测试Exception类型使用if块的内容,因为您可以使用多个catch语句来执行此操作.