How to throw an exception to users in drupal

With custom development come a lot of entry points for users. This snippet throws access denied for users that are too curious on some paths.

use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

if(!$contest->isActive()) {
  throw new AccessDeniedHttpException();
}