Example of error handling in OO PHP

The function below tests if a parameter value is passed. If not, it throws an exception.

Throwing exception...

"; throw new Exception("Not an integer!"); } return true; } //trigger exception in a "try" block try { checkVal("rfgdrf"); echo '

Value was OK

'; // If we get here, exception was not thrown } //catch exception catch(Exception $e) { echo 'Message: ' .$e->getMessage(); } // getMessage() reference here: https://www.w3schools.com/php/ref_exception_getmessage.asp ?>