2008年9月23日星期二

Re: [fw-mvc] best practice for errors occurring in plugins

-- Guillaume Oriol <goriol@technema.fr> wrote
(on Wednesday, 17 September 2008, 12:12 AM -0700):
> I've read a few posts from the archive regarding the way to handle exceptions
> occurring in a plugin. In one of them, Matthew W. answers:
>
>
> > What the statement "It is not intended to catch exceptions raised in
> > other plugins or routing" means is that the ErrorHandler plugin can only
> > catch exceptions raised within your action controllers, not exceptions
> > raised in plugins or other areas of responsibility during the dispatch
> > cycle. You can always do your own try/catch blocks and forward as noted
> > above.
> >
>
> Is it intentional to not catch in ErrorController the exceptions raised in
> plugins or is there a hidden technical problem?

It's a technical issue currently. Right now, we have a single try/catch
block within the dispatch loop. To catch all plugin exceptions, we'd
need to either introduce try/catch blocks in each hook, or one over the
entire body of dispatch(). The primary issues are that this leads to a
slight BC break, and also degrades performance. Secondarily, there are
hooks where dispatching a new request would be problematic --
for instance, routeStartup/Shutdown() and dispatchLoopShutdown().

> And, as the way to handle errors is different depending on the place they
> occur, what is the best practice for application errors? To use in every
> case a forward to a specific action in the error controller?

Something I've tried is this:

try {
$front->dispatch();
} catch (Exception $e) {
// redirect to error page or display placeholder
}

I do the above with throwExceptions() disabled -- this then catches any
plugin exceptions that occur, and handles them differently.

We would like to move towards a standard error mechanism for plugins and
application code, but, as noted above, have some questions to resolve
first.

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: