I am only learning Exceptions and error reporting, and I am trying to understand behaviours of try/catch and perhaps other methods that I don't know yet. I have code like this:
function nameless(....) {
if(!$condition) {
throw new Exception('Condition not met');
}
[someCode ...]
return $result;
}
I want to make sure that someCode
only executes if the condition is met. Would a structure like this guarantee that it?
Before talking about putting the rest of the code in an else
block, or other methods, I want to know if there is some way to execute nameless()
in a way that would continue its execution after it throws the exception.
Once I know that, I would like to know if there are better/worse ways of doing things and if this particular example is poor or it's one of a hundred equally valid ways to do this. Thank you.