SystemExceptions are already logged when the System ServiceProvider listens to the Message Logged event, this code used to be for ApplicationExceptions to bypass the fact that they were explicitly ignored by October's core exception handler.
ApplicationExceptions were added 27 Jan 2015 in 6a68036260
ApplicationExceptions were explicitly ignored in the core exception handler on 16 Feb 2015 in 237d97d87a (diff-b6bf0348130fdd1311473a97536310cdR20) and were explicitly logged in the System exception handler on the same day in 7b52e07b65 (diff-547f5794a63e9f138c33b20de8649b7eR20-R31)
Not sure why that was originally the case, but we've made the decision that ApplicationExceptions shouldn't be logged by default as they should occur semi-regularly in a healthy application (mostly as an expression of complex logical validation that triggers them based on bad user input): https://github.com/octobercms/october/pull/4569#issuecomment-550172508Fixesoctobercms/october#5253.
If we don't have this method called, then the controller returns an object. From then on, [Symfony converts this object in to a string](https://github.com/symfony/HttpFoundation/blob/master/Response.php#L406). This string is **not just the content of the view**, but the headers as well.
After attaching this method, `handleCustomError()` returns a string and everything works as expected.
Previously Twig syntax errors inside a component partial would show the incorrect file and line number. This is fixed.
Also simplified the approach so the stack trace is not hidden inside a closure.