CakePHP is a wonderful framework, but it really drops the ball when it comes to practical error management. In production environments (DEBUG = 0), only 404 or 500 errors are displayed to the user, and no errors are written to the log files.
This means runtime errors (e.g. an unexpected divide-by-zero) are not logged, and service errors (e.g. when a paypal checkout fails) are not explained to the user.
To solve these two problems we override php’s error handler to enable production error logging, and cake’s error handler to allow forward facing error pages.
Part 1: To enable production error logging, we can override cake’s production error handling code by conditionally setting DISABLE_DEFAULT_ERROR_HANDLING. This code only kicks in when cake is in production and logs all notices and warnings in the cake log file.
Part 2: To enable forward facing user error pages, we can define an AppError class. This code allows you to set up custom error handlers, and decide how you want to handle each - be it publicly displayed, logged or mailed to the site managers.
Both of these solutions are independent of each other, and provide a way to practically manage error handling in your CakePHP deployment.
I have also opened a RFC to get this behavior included in cake’s core.