how do 404 pages work? How does the 404 page you can define in /admin/config/system/site-information work?

I found Drupal\system\Controller\Http4xxController->on404(), but how does that display whatever path I definied in basic site settings?

I'm trying to deliver a 410 when a page is deleted. I hve a database table with deleted paths, an InboundPathProcessorInterface to call a custom controller. Now I want to output the exact same thing as a 404, just with another status code.

Alternativly, how do I get the content of a given system path (i.e. node/123) to output in a Symfony\Component\HttpFoundation\Response?
For the configured custom path:

CustomPageExceptionHtmlSubscriber::on404

   public function on404(GetResponseForExceptionEvent $event) {
    $custom_404_path = $this-&gt;configFactory-&gt;get('system.site')-&gt;get('page.404');
    if (!empty($custom_404_path)) {
      $this-&gt;makeSubrequestToCustomPath($event, $custom_404_path, Response::HTTP_NOT_FOUND);
    }
  }


If no custom path is configured the subrequest is built for '/system/404' pointing to the controller you've mentioned:

DefaultExceptionHtmlSubscriber::on404

  public function on404(GetResponseForExceptionEvent $event) {
    $this-&gt;makeSubrequest($event, '/system/404', Response::HTTP_NOT_FOUND);
  }


To customize other status codes than 403 or 404 extend DefaultExceptionHtmlSubscriber and override on4xx().