cakephp - try/catch an Action
Posted
by joshs
on Stack Overflow
See other posts from Stack Overflow
or by joshs
Published on 2010-03-24T04:47:47Z
Indexed on
2010/03/24
4:53 UTC
Read the original article
Hit count: 343
cakephp
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.
© Stack Overflow or respective owner