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
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.
}
}
}
-
Thank you! Would this need to be added into error.php or index.php ? Commented Jun 7, 2022 at 14:24
-