I use TYPO3 version 10.4.23 with news extension 9.1.1
I inject the NewsRepository in my Extension to get news-title with following (simplified) code:
class MytestController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
protected $newsRepository;
public function injectNewsRepository(\GeorgRinger\News\Domain\Repository\NewsRepository $newsRepository) {
$this->newsRepository = $newsRepository;
}
public function listAction() {
$newsUid = 1234;
$news = $this->newsRepository->findByUid($newsUid);
$title = $news->getTitle();
}
}
This works fine when $newsUid is an existing ID. But if a $newsUid doesn't exist in Database, an exception is thrown:
Exception handler (WEB): Uncaught TYPO3 Exception: Return value of GeorgRinger\News\Domain\Repository\NewsRepository::findByUid() must be an instance of GeorgRinger\News\Domain\Model\News, null returned | TypeError thrown in file /www/typo3conf/ext/news/Classes/Domain/Repository/NewsRepository.php in line 355.
Unfortunately I can't catch this exception because it happens in the news extension.
What possibility do I have to catch this error in my extension?