Skip to content

Commit

Permalink
Add docs for cakephp/cakephp#17960
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 11, 2024
1 parent 249f017 commit f1a52f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions en/appendices/5-2-migration-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
24 changes: 24 additions & 0 deletions en/development/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f1a52f6

Please sign in to comment.