How to avoid “if” chains?

You can use an && (logic AND): if (executeStepA() && executeStepB() && executeStepC()){ … } executeThisFunctionInAnyCase(); this will satisfy both of your requirements: executeStep<X>() should evaluate only if the previous one succeeded (this is called short circuit evaluation) executeThisFunctionInAnyCase() will be executed in any case

Java: Exceptions as control flow?

Generally exceptions are expensive operations and as the name would suggest, exceptional conditions. So using them in the context of controlling the flow of your application is indeed considered bad practice. Specifically in the example you provided, you would need to do some basic validation of the inputs you are providing to the StringMatch constructor. … Read more