PHP Exception getMessage is a method that is used to get the error message associated with an exception object. It returns a string that contains the error message generated by the code that threw the exception. It is used to debug code and identify errors in the application.
This code will catch an exception and then it will use the getMessage() method to get the error message associated with the exception. Then it will print the error message on the screen.
Example 2:
function divide($num1, $num2){ if($num2 == 0){ throw new Exception("Cannot divide by zero"); } return $num1 / $num2; }
This code is a function that divides two numbers. If the divisor is zero, it will throw an exception with the error message "Cannot divide by zero". When calling the function, it is wrapped in a try-catch block that catches the exception and prints the error message on the screen.
Package library: PHP Standard Library (SPL)
PHP Exception::GetMessage - 2 examples found. These are the top rated real world PHP examples of Exception::GetMessage extracted from open source projects. You can rate examples to help us improve the quality of examples.