Basic Use of Exceptions (Cont.)
The code below checks whether the HTTP host is located at the CEM, whose URL includes the string “undcemcs01.und.edu .”
It throws an exception and catches it:
The checkHost function is created.
It checks if the HTTP host is located at undcemcs01.und.edu, for example.
If it is not, an exception is thrown.
The checkHost function is called in a “try” block.
The HTTP host is found by using the PHP variable $_SERVER.
The exception within the checkHost function is thrown.
The “catch” block retrieves the exception and creates an object ($e) containing the exception information
The error message from the exception is echoed by calling $e->getMessage from the exception object.
The string function strstr(string,search) searches for the first occurrence of a string inside another string.