phpslim v3,检查命名路由是否存在

phpslim v3, check if named route exists

如何检查 phpslim v3 中是否存在命名路由? 我似乎无法对不存在的名称执行 try/catch,执行仍然存在错误。

try {
    $redirect_to = $this->router->pathFor($dynamic);
}
catch (\Exception $e) {
    $redirect_to = $this->router->pathFor('dashboard');
}

谢谢

try {
    $this->router->getNamedRoute($dynamic);
    echo "Route found.";
} catch (RuntimeException $e) {
    echo "Route not found!";
}

参见:https://github.com/slimphp/Slim/blob/3.x/Slim/Router.php#L268