Is the order of the catch blocks important?

Just making sure that I understand it well. Is the correct circuit correct? Catching the most specific exceptions, primarily to detect wider exceptions with a common catch at the end of the catch block set.

try { some code } catch(SomeSpecificException ex) { } catch(LessSpecificException ex) { } catch { //some general exception } 
+6
c # exception
source share
1 answer

I believe that this will not allow you to write it in the wrong order.

This creates an error:

 try { throw new OutOfMemoryException(); } catch(Exception ex) { "B".Dump(); } catch(OutOfMemoryException ex) { "A".Dump(); } 
+5
source share

All Articles