i would remove this whole if and the one with instanceof Route and simply try-catch around the router->generate call and wrap that exception into the SeoAwareException. then you can leave it up to the router to do all the checks for you.