Is it necessary to always catch `Nette\Application\AbortException` when returning a Response from Presenter?

matronator
Member | 37
+
0
-

I was just writing code in our CRM at work and noticed a warning when using $this->sendJson() about unhandled exception Nette\Application\AbortException. I've seen this same warning many times, so I assume every $this->send...() method throws this exception.

Is it then necessary to always wrap the response in a try...catch block? Because sending responses is a pretty common thing, so it seems redundant to always have to catch the AbortException. Is it really necessary and what are the dangers of not handling it?

Thanks!

Marek Bartoš
Nette Blogger | 1176
+
+6
-

AbortException is just internal mechanism for finishing request processing, you may completely ignore it.
I guess you are using PHPStorm? It likes to report most of the exceptions. @DavidGrudl may we change exceptions that are not intended to be caught to extend LogicException instead of Exception? That should suppress all IDE warnings.

mystik
Member | 292
+
+3
-

In fact it is dangerous to trying to handle it. As @MarekBartoš already pointed out ot is integral part of how sending respose in Nette works under the hood. It should always bubble up from your action/render methods.