C
C#2y ago
surwren

Proper C multicatch syntax

I saw in Java that you can do multicatch blocks (see image) I also looked it up on stackoverflow: https://stackoverflow.com/questions/136035/catch-multiple-exceptions-at-once However there seems to be several methods listed in the thread. What's the c# convention for multicatch blocks?
Stack Overflow
Catch multiple exceptions at once?
It is discouraged to simply catch System.Exception. Instead, only the "known" exceptions should be caught. Now, this sometimes leads to unnecessary repetitive code, for example: try { ...
1 Reply
HimmDawg
HimmDawg2y ago
We either check for individual exceptions with multiple ifs Or we have this
catch (Exception ex) when (
ex is ...
|| ex is ...
|| ex is ...
)
catch (Exception ex) when (
ex is ...
|| ex is ...
|| ex is ...
)