为什么抛出异常2在连续不产生可达code警告? [英] Why does throwing 2 exceptions in a row not generate an unreachable code warning?

查看:137
本文介绍了为什么抛出异常2在连续不产生可达code警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么的$ C $以下行C不能创建一个编译器警告?

Why do the following lines of code not create a compiler warning?

void Main()
{
  throw new Exception();
  throw new Exception();
}

在我看来,编译器应该告诉你,第二个抛出异常无法达成。

As I see it, the compiler should inform you that the second throw exception cannot be reached.

推荐答案

这显然是一个编译器缺陷,它被介绍了C#3.0 - 对各地,我大量重构的可达性检查的时间。这大概是我不好,对不起。

It is clearly a compiler bug, and it was introduced in C# 3.0 -- right around the time that I heavily refactored the reachability checker. This is probably my bad, sorry.

该错误是完全良性的;基本上,我们只是忘了在警告记者的情况。我们正确地生成的可达性信息;正如其他人所指出的,我们正确地修剪出前codeGEN不可达code。

The bug is completely benign; basically, we just forgot a case in the warning reporter. We generate the reachability information correctly; as others have noted, we correctly trim out the unreachable code before codegen.

该错误无非是在警告发电机失踪案件多。我们有一些棘手的code在那里,确保我们当你code的一些大节不可达不报告是数不胜数警告。编译器有code对无条件的goto(GOTO,破发,继续),有条件的goto特别报告警告(如果,而等)的try-catch-finally程序(其中包括表单相当于的try-catch-最后,就像锁和使用),块,回报(收益率回报和定期回报),局部声明,标号语句,开关和前pression声明。

The bug is nothing more than a missing case in the warning generator. We have some tricky code in there that ensures that we do not report a zillion warnings when you make some large section of code unreachable. The compiler has code for specifically reporting warnings on unconditional gotos ("goto", "break", "continue"), conditional gotos ("if", "while" and so on), try-catch-finally (which includes forms equivalent to try-catch-finally, like lock and using), blocks, returns (yield return and regular return), local declarations, labelled statements, switches, and expression statements.

你看见那个名单上的扔声明?我也不。这是因为我们忘记了它。

Do you see "throw statements" on that list? Me neither. That's because we forgot it.

带来的不便道歉。我会发一张纸条给QA,我们会尽快为这个修复到语言的未来版本。

Apologies for the inconvenience. I'll send a note to QA and we'll get a fix for this into a future version of the language.

感谢您将要对我的关注。

Thanks for bringing this to my attention.

这篇关于为什么抛出异常2在连续不产生可达code警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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