Menu

← Back to nette.*

Error Identifier: nette.rethrowException

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

use Nette\Application\AbortException;
use Nette\Application\UI\Presenter;

class ProductPresenter extends Presenter
{
	public function actionRedirect(): void
	{
		try {
			$this->redirect('Homepage:');
		} catch (\Throwable $e) {
			// logged or silently swallowed
		}
	}
}

Why is it reported? #

This error is reported by phpstan/phpstan-nette.

Certain Nette methods (such as redirect(), forward(), sendJson(), sendResponse(), and terminate() on Presenters) use exceptions for control flow. For example, redirect() throws Nette\Application\AbortException to terminate the current request and initiate the redirect. If the code wraps such a call in a try/catch block that catches \Exception or \Throwable without rethrowing the control-flow exception, the redirect (or other intended action) will silently fail.

How to fix it #

Catch and rethrow the control-flow exception before catching the general exception:

 <?php declare(strict_types = 1);
 
 use Nette\Application\AbortException;
 use Nette\Application\UI\Presenter;

 class ProductPresenter extends Presenter
 {
 	public function actionRedirect(): void
 	{
 		try {
 			$this->redirect('Homepage:');
-		} catch (\Throwable $e) {
-			// logged or silently swallowed
+		} catch (AbortException $e) {
+			throw $e;
+		} catch (\Throwable $e) {
+			// handle other exceptions
 		}
 	}
 }

Or narrow the catch clause so it does not intercept the control-flow exception:

 <?php declare(strict_types = 1);
 
 use Nette\Application\UI\Presenter;

 class ProductPresenter extends Presenter
 {
 	public function actionRedirect(): void
 	{
 		try {
 			$this->redirect('Homepage:');
-		} catch (\Throwable $e) {
-			// logged or silently swallowed
+		} catch (\InvalidArgumentException $e) {
+			// handle specific exception
 		}
 	}
 }

How to ignore this error #

You can use the identifier nette.rethrowException to ignore this error using a comment:

// @phpstan-ignore nette.rethrowException
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: nette.rethrowException

Rules that report this error #

  • PHPStan\Rule\Nette\RethrowExceptionRule [1] phpstan/phpstan-nette

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.