diff --git a/en/appendices/5-2-migration-guide.rst b/en/appendices/5-2-migration-guide.rst index bc9fecb776..57b11b0001 100644 --- a/en/appendices/5-2-migration-guide.rst +++ b/en/appendices/5-2-migration-guide.rst @@ -12,3 +12,11 @@ Behavior Changes a name that is already defined. This change aims to prevent rules from being overwritten by accident. +New Features +============ + +Error +----- + +- Custom exceptions can have specific error handling logic defined in + ``ErrorController``. diff --git a/en/development/errors.rst b/en/development/errors.rst index 04385d0e7c..3121aa1a38 100644 --- a/en/development/errors.rst +++ b/en/development/errors.rst @@ -210,6 +210,30 @@ prefix. You could create the following class:: This controller would only be used when an error is encountered in a prefixed controller, and allows you to define prefix specific logic/templates as needed. +Exception specific logic +------------------------ + +Within your controller you can define public methods to handle custom +application errors. For example a ``MissingWidgetException`` would be handled by +a ``missingWidget()`` controller method, and CakePHP would use +``templates/Error/missing_widget.php`` as the template. For example:: + + namespace App\Controller\Admin; + + use App\Controller\AppController; + use Cake\Event\EventInterface; + + class ErrorController extends AppController + { + public function missingWidget(MissingWidgetException $error) + { + // You can prepare additional template context or trap errors. + } + } + +.. versionadded:: 5.2.0 + Exception specific controller methods and templates were added. + .. _custom-exceptionrenderer: Custom ExceptionRenderer