Show access denied in custom page without permissions I have a requirement where based on user ID displaying the page. If not show Access Denied.
Drupal 7 we have drupal_access_denied().
What is it in Drupal 8?
As a replacement for drupal_access_denied() this in Drupal 8 you can use :

if(empty($userId)){

throw new \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException();

}


This shows the access denied page in the browser.