I dont want to catch some exception. Can I do it somehow?
Can I say something like this:
catch (Exception e BUT not CustomExceptionA)
{
}
?
I dont want to catch some exception. Can I do it somehow?
Can I say something like this:
catch (Exception e BUT not CustomExceptionA)
{
}
?
You can filter it:
And of course you can catch it and rethrow it:
After being schooled by @Servy in the comments, I thought of a solution that'll let you do [what I think] you want to do. Let's create a method
IgnoreExceptionsFor()
that looks like this:This can then be called like this:
That way, every line except for the one with
PreventExceptionsFor()
will throw exceptions normally, while the one insidePreventExceptionsFor()
will get quietly passed over.Starting with C# 6, you can use an exception filter:
First off, it's bad practice to catch Exception unless you log and re-throw it. But if you must, you need to catch your custom exception and re-throw it like so: