The rule for catch clauses is that the first match is the one that's selected. Unlike overloaded functions, there is no notion of "best" match.

So in the example code, if stuff is false, the body for catch(derivedException) would be executed, because the thrown exception has type derivedException; if stuff is true, the body for catch(baseException) would be executed because the first catch clause doesn't match, but the second one does..

If the catch clauses were reversed, then regardless of the value of stuff, the body of the first catch clause (catch(baseException)) would be executed, because both exceptions can be caught by the base type.