AbortException – annotate, suppress or just ignore?

15 days ago

Member | 10


please take a look at following code:

public function renderPage()
    $this->sendResponse(new TextResponse('Hello.'));

This causes a linter or even PHPStorm produce warning: Unhandled AbortException. I underestand why it does so, but I wonder what is a good solution for this – how do you deal with it?

  1. You can simply ignore the warning.
  2. You can set AbortException as unchecked. That's working, but kinda non-standard, usually only RuntimeException and its descendants are ignored.
  3. You can suppress the sendResponse() or redirect() with an annotation.
  4. You can annotate action method with @throws.

Problem here is that such methods do not throw exceptions exceptionally, but always – it's their primary behavior. Extending the RuntimeException would be solution, but it's not intended for this use, as far as I know. Also, ignoring the fact that methods throws an exception can lead to undetected dead code.

Maybe we miss something like @unchecked annotation on exception classes, or yet better @expected on methods throwing those?