Suppose we want to set only one exception handler function for all exceptions in the scraper program. This exception handler might be working for a multi-level program. Here is how it works in PHP.

At the beginning of the main scraper’s code, insert this pattern:

after that insert the handler directive to set a previously-defined exception handler function:

Note that the header (‘HTTP/1.1 500 Internal Server Error’) should be set before we do any output in the scraper’s code. Otherwise the header’s collision exception will be issued with no desired output in this exception_handler function.