Fix shutdown and afterDispatch events not being fired on exceptions.

When exceptions are fired the shutdown and afterDispatch events should
be properly fired. This allows plugins and application code to ensure it
is run. Of course this creates the potential for infinite loops if these
events also trigger an exception.

Refs #5208
Merge pull request #5252 from cakephp/issue-5208

Fix shutdown and afterDispatch events not being fired on exceptions.