How can I catch specific exceptions?

Using Java, I liked to have specific exceptions classes on the catch clause, like this.

catch (FileNotFoundException | SQLException e)

Now, I'd like to have the same type of catch clause in C#. is there a way to configure it so it has a similar behavior?

Upvotes: 2

Views: 83

Answers (1)

DCCoder
DCCoder

Reputation: 1628

As others have mentioned this isn't an IDE specific feature but more of a language feature. Within your catch statement you can identify specific exceptions to catch such as:

catch (InvalidCastException e)
{
}

or you can get more in-depth with exception filters

catch (ArgumentException e) when (e.ParamName == "…")
{
}

Rider Solution

If you are wanting rider to look for specific exceptions regardless this can be done through the Debug window. Simply open your debug window then click View breakpoints and exceptions...View breakpoints and exceptions....

Next you will click the plus sign at the top of the new window and choose CLR Exception Breakpoints CLR Exception Breakpoints

On the new window you can choose which exceptions you want the debugger to be on the lookout for.

Exception selection

Upvotes: 1

Related Questions