根据CLI标准(分区IIA,第19章)和System.Reflection.ExceptionHandlingClauseOptions枚举的MSDN参考页面,有四种不同的异常处理程序块:
鉴于这些简短的解释(引自CLI标准,顺便说一句),这些应该映射到C#,如下所示:
catch (FooException) { … }Catch FooException When booleanExpression)finally { … }catch { … }一个简单的实验表明,这种映射不是.NET的C#编译器真正做的事情:
// using System.Linq;
// using System.Reflection;
static bool IsCatchWithoutTypeSpecificationEmittedAsFaultClause()
{
try
{
return MethodBase
.GetCurrentMethod()
.GetMethodBody()
.ExceptionHandlingClauses
.Any(clause => clause.Flags == ExceptionHandlingClauseOptions.Fault);
}
catch // <-- this is what the above code …Run Code Online (Sandbox Code Playgroud)