I am trying to catch an error on object creation, because this object can and should sometimes throw an error.
try {
$obj = new MyObject();
} catch (Exception $e) {
echo 'Caught exception: ';
}
I want to do a lot of things with this new object, but only IF it was created without throwing an exception.
The problem is that I do not wish to do all these things inside the try catch block. How would I accomplish this?
Thanks a lot
Michael
I really can’t see any reason for what you are asking, but maybe the best thing is to do all the other stuff in a function that you call from the try/catch block…
Otherwise, to do literally as you seem to be asking, you could set a switch before the try/catch block to on, and set it to off in the catch block. That way you can test the switch to see whether to execute all your other stuff.