cakephp - try/catch an Action
- by joshs
I would like to somehow apply a try catch statement to all Actions as a backstop for any uncaught exceptions.
I think this would be particularly helpful for Ajax Actions, because the catch statement could send back a default 4xx status code. Prototype's onFailure() function could then do the client-side error handling.
How can I do this without wrapping the Action call with a try/catch in the cake dispatcher like this:
try {
output = $controller->dispatchMethod($params['action'], $params['pass']);
}
catch {...}
Does anybody have a suggestion or another workable strategy for gaining this functionality without touching the dispatcher?
How do people feel about putting exception handling in the Displatcher? I imagine when cake drops php 4 support, there will be a built-in mechanism for this.