Fun*_*ung 14 c# vb.net exception-handling vb.net-to-c#
在VB.NET中,我经常Catch…When
:
Try
…
Catch e As ArgumentNullException When e.ParamName.ToUpper() = "SAMPLES"
…
End Try
Run Code Online (Sandbox Code Playgroud)
是否有C#相当于Catch…When
?
如果可能if
的catch
话,我不想诉诸于使用声明.
cru*_*zer 15
Catch…When
在C#中没有相同的东西.你真的不得不求助于if
你的内部声明catch
,然后重新抛出你的条件是否满足:
try
{
…
}
catch (ArgumentNullException e)
{
if ("SAMPLES" == e.ParamName.ToUpper())
{
… // handle exception
}
else
{
throw; // condition not fulfilled, let someone else handle the exception
}
}
Run Code Online (Sandbox Code Playgroud)
Joe*_*Joe 13
这个功能是为C#6宣布的.现在可以写了
try { … }
catch (MyException e) when (myfilter(e))
{
…
}
Run Code Online (Sandbox Code Playgroud)
您现在可以下载Visual Studio 2015的预览版以查看它,或者等待官方发布.
归档时间: |
|
查看次数: |
4511 次 |
最近记录: |