Quantcast

Catching exceptions thrown by view templates

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Catching exceptions thrown by view templates

demiankatz

In ZF1, if a PHP view template throws an exception, the framework directs it to the ErrorController.

 

In ZF2 (or at least, in my particular app), if a PHP view template throws an exception, the application dies with an “uncaught exception” error.

 

Is there a simple way to catch exceptions thrown in the view context?  I realize that in general it’s probably not a good idea to have templates throwing exceptions, but it would be nice to have a safety net to avoid the “white screen of death” in unexpected circumstances.

 

thanks,
Demian

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Catching exceptions thrown by view templates

weierophinney
Administrator
-- Demian Katz <[hidden email]> wrote
(on Thursday, 16 August 2012, 06:26 PM +0000):

> In ZF1, if a PHP view template throws an exception, the framework directs it to
> the ErrorController.
>
>  
>
> In ZF2 (or at least, in my particular app), if a PHP view template throws an
> exception, the application dies with an “uncaught exception” error.
>
>  
>
> Is there a simple way to catch exceptions thrown in the view context?  I
> realize that in general it’s probably not a good idea to have templates
> throwing exceptions, but it would be nice to have a safety net to avoid the
> “white screen of death” in unexpected circumstances.

We could likely add a listener around the view event, which would allow
doing a try/catch around rendering. At this stage, I'd recommend it for
2.1, as it's backwards compatible, and that will give us more time to
test it thoroughly.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: Catching exceptions thrown by view templates

demiankatz
>> Is there a simple way to catch exceptions thrown in the view context?  I
>> realize that in general it’s probably not a good idea to have templates
>> throwing exceptions, but it would be nice to have a safety net to avoid the
>> “white screen of death” in unexpected circumstances.

> We could likely add a listener around the view event, which would allow
> doing a try/catch around rendering. At this stage, I'd recommend it for
> 2.1, as it's backwards compatible, and that will give us more time to
> test it thoroughly.

Sounds reasonable.  Much as I'd love to see it in 2.0, I understand your desire to get this thing out the door in working order (I'm in a similar situation over here).  Is this worth opening a ticket for?  Is there a 2.1 feature wiki somewhere I should edit?  I don't feel too confident about implementing this myself just yet, though if nobody else is likely to have time or interest, I can certainly give it a try (though a point in the right general direction -- even just the names of the most relevant classes to start studying -- would be a big help).

- Demian
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Catching exceptions thrown by view templates

weierophinney
Administrator
-- Demian Katz <[hidden email]> wrote
(on Thursday, 16 August 2012, 11:58 PM +0000):

> >> Is there a simple way to catch exceptions thrown in the view context?  I
> >> realize that in general it’s probably not a good idea to have templates
> >> throwing exceptions, but it would be nice to have a safety net to avoid the
> >> “white screen of death” in unexpected circumstances.
>
> > We could likely add a listener around the view event, which would allow
> > doing a try/catch around rendering. At this stage, I'd recommend it for
> > 2.1, as it's backwards compatible, and that will give us more time to
> > test it thoroughly.
>
> Sounds reasonable.  Much as I'd love to see it in 2.0, I understand
> your desire to get this thing out the door in working order (I'm in a
> similar situation over here).  Is this worth opening a ticket for?  Is
> there a 2.1 feature wiki somewhere I should edit?  I don't feel too
> confident about implementing this myself just yet, though if nobody
> else is likely to have time or interest, I can certainly give it a try
> (though a point in the right general direction -- even just the names
> of the most relevant classes to start studying -- would be a big
> help).

Add it as a feature request to the issue tracker
(http://framework.zend.com/issues).  Make sure you do it on the ZF2
project (vs the ZF (version 1) project).

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: Catching exceptions thrown by view templates

demiankatz
> Add it as a feature request to the issue tracker
> (http://framework.zend.com/issues).  Make sure you do it on the ZF2
> project (vs the ZF (version 1) project).

Done:

http://framework.zend.com/issues/browse/ZF2-473

thanks,
Demian
Loading...