-- Mike Fern <[EMAIL PROTECTED]> wrote
(on Wednesday, 15 August 2007, 11:07 PM +0700):
> >On 8/15/07, Matthew Weier O'Phinney <[EMAIL PROTECTED]> wrote:
> >
> >
> > $response->isException() indicates an exception exists. You can then
> > fetch the exception stack (response object puts all exceptions trapped
> > into an internal array) by using:
> >
> >     $exceptions = $response->getException();
> >
> > You can then loop over each exception in that list to get stack traces.
> >
> 
> Thanks for the answer but after more tinkering I think I should
> process the stack trace output of native "getTraceAsString" from the
> exception class instead.
> 
> Since "ne" is a non existent action in http://sitename.com/dummy/ne,
> after evaluating this line:

First off, why aren't you creating an ErrorController to use with the
ErrorHandler plugin. This will help with precisely the situation above.
Please read the docs on the ErrorHandler:

    
http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler

> $response = $controller->dispatch();
> 
> A fatal error will be sent to the browser because exception thrown
> from $controller->dispatch() is not caught. Stack traces are properly
> outputted to the screen.
> 
> Now a try-catch block is added and $response is now within a try block:
> try {
>     $response = $controller->dispatch();
>     ..remaining code
> } catch (Exception $e) {
>     $traces = $e->getTraceAsString();
>     $message = $e->getMessage();
>    ...beautify the stack traces along with error message
> }
> 
> The "remaining code" part won't be evaluated because exception has
> been thrown and caught. Because $response is still unset,
> "getException" method can not be used, hence I should fall back to the
> basic exception handler.

So create a response object and pass it to dispatch:

    $controller->setResponse(new Zend_Controller_Response_Http());
    try {
        $controller->dispatch();
    } catch (Exception $e) {
        ...
    }

> Not a pretty neat solution, I'll be happy to see other approaches to
> error trapping and handling.

As noted above, use the ErrorHandler. You can then grab the exception
stack from the response in your error controller's error action, and do
what you need to do with it (format and return trace strings, etc).

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to