When failed to access something on the web (api, database), how would I stop executing the rest of the script and log the error in the log file? Well, and so that the visito
and so that the visitor wouldn't see the exact cause but rather they would see my custom message
I would suggest you to go through this excellent article by David Walsh on custom error handling in PHP.
You can use set_error_handler() function for that.
how would I stop executing the rest of the script and log the error in the log file?
There is a default function of PHP to log errors; error_log
Example from PHP.net:
.
More Resources:
This is also good article covering most of it related to error handling.