0

As per the title, how can we catch a RouteNotFoundException? For time constraints, instead of creating a custom component we opted for some hand-waving, and decided to display custom content at non-routed URL's, and it's working, but we would like to catch the exception. I tried acting on error.php and index.php, but to no avail.

1 Answer 1

1

In J4 exceptions can be handled by system plugins with onError event:

use Joomla\CMS\Event\ErrorEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Exception\RouteNotFoundException;

class PlgSystemExample extends CMSPlugin
{
    public function onError(ErrorEvent $event)
    {
        if ($event->getError() instanceof RouteNotFoundException)
        {
            // Handle the exception.
        }
    }
}
2
  • Thank you! Would this need to be added into error.php or index.php ? Jun 7 at 14:24
  • No, it's a plugin.
    – Sharky
    Jun 8 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.