Hey man
First you need register exception for this we have many options for it, for example Registering it into dispatcher
$di->set('dispatcher', function () {
$eventsManager = new EventsManager();
$eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
//controller or action doesn't exist
$object = $event->getData();
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward([
'controller' => 'errors',
'action' => 'index'
]);
return false;
case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
$dispatcher->forward([
'controller' => 'errors',
'action' => 'show404'
]);
return false;
}
}
});
And created a controller name errors and action index or anthing you want to create it