sil*_*lla 6 .net c# exception-handling
我不想抓住一些例外.我能以某种方式做到吗?
我可以这样说:
catch (Exception e BUT not CustomExceptionA)
{
}
Run Code Online (Sandbox Code Playgroud)
?
Ste*_*e B 21
try
{
// Explosive code
}
catch (CustomExceptionA){ throw; }
catch (Exception ex)
{
//classic error handling
}
Run Code Online (Sandbox Code Playgroud)
try
{
}
catch (Exception ex)
{
if (ex is CustomExceptionA)
{
throw;
}
else
{
// handle
}
}
Run Code Online (Sandbox Code Playgroud)
从C#6开始,您可以使用异常过滤器:
try
{
// Do work
}
catch (Exception e) when (!(e is CustomExceptionA))
{
// Catch anything but CustomExceptionA
}
Run Code Online (Sandbox Code Playgroud)