Throw an exception when something goes wrong and catch it where you can handle it.
throw new Exception("message");try { } catch (Exception $e) { } finally { }- Catch several types:
catch (TypeError | ValueError $e) - Create your own:
class PaymentException extends Exception {}