Throwing Exceptions in CakePHP4

Throwing Exceptions in CakePHP4

In your controller:

use Cake\Http\Exception\NotFoundException;

In your method:

if(.....) {
  throw new NotFoundException(__('Article not found'));
}

 

Other Resources:

For a complete list of excemptions in CakePHP4, see the documentation: 
https://book.cakephp.org/4/en/development/errors.html#built-in-exceptions-for-cakephp

Share this Post