I'm trying to figure out how to make sure that I'm sent an email if an error occurs within the script that I'm calling via URL. I thought that by throwing a PHP Exception, the Scheduled Task would consider that a good reason to email me ... but no.
Is there a way to ensure that the Cron notifies me if the script itself throws and exception, or something similar?
try {
$connect = $rets->Login();
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
throw new Exception("caught for demonstration");
}
For Operation System exit code which is not equal to 0 is only good reason to understand that something goes wrong :-)
Scheduled task which executes your PHP script is looks like OS command which execute proper PHP binary:
If exit code of this command is not equal to 0 you'll get email message.
Try to replace:
with: