<?php
use TYPO3\CMS\Core\Http\ImmediateResponseException;   
use TYPO3\CMS\Core\Utility\GeneralUtility;            
use TYPO3\CMS\Frontend\Controller\ErrorController;    

class SomeController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
    public function someAction($id)
    {
        if (!SomeModel::find($id)) {
            $response = GeneralUtility::makeInstance(ErrorController::class)
                ->pageNotFoundAction($GLOBALS['TYPO3_REQUEST'], 'Record not found.');
            throw new ImmediateResponseException($response, 1617116194);    
        }
    }
}