By default, the framework handles most situations where errors occur, displaying an error page to the user when 4xx and 5xx HTTP exceptions are thrown, with a backtrace and code preview when the debug mode is enabled.
In this recipe, we'll see how you can customize this experience for your users and also some more advanced techniques to gain full control over error handling.
As we'll simply use this recipe to demonstrate a custom exception, let's create a controller that will serve as an example. So, create a file named BrokenController.php
in app/Controller/
, and introduce the following code in it:
<?php App::uses('AppController', 'Controller'); class BrokenController extends AppController { }