About this question
There is a recommendation not to use an Exception to control the flow of execution. This gives me a reason for doubt when I do something like this:
public void initApplication(String input) {
try {
MyClass mClass = new mClass(input);
saveToDatabase(mClass);
updateSettingsTheAppIsReady();
} catch (CancelPreparationsException e) {
showErrorMessageToUser();
doRollbacks();
}
}
mClass instantiation, save operation to a database, settings update may go wrong, each of them throw their own exceptions, which I catch within the methods/classes and throw my custom exception to stop the initApplication() method execution.
This sounds an easier way than having preconditions checking like:
Create a MyClass object.
Check the MyClass object is created then save it to db.
Ensure the object was saved in db then update settings.
Is it really not a recommended way of using the Exception to control the flow? Thank you.