Re: Restore output buffer in case of exceptions
| From: | Mehmet Yavuz Selim Soyturk | Date: | Sun, 18 Nov 2007 01:20:15 +0000 |
| Subject: | Re: Restore output buffer in case of exceptions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-33230@lists.php.net to get a copy of this message | ||
On Nov 18, 2007 1:38 AM, Evert | Rooftop <evert@rooftopsolutions.nl> wrote:
> Generally I make sure that the parts of my code that start an output
> buffer are also responsible for closing the output buffer.. so something
> like this wouldn't be uncommon in my code..
>
>
> ob_start();
> try {
> do_something();
> } catch (Exception $e) {
> ob_end_clean();
> throw $e;
> }
>
> $data = ob_get_clean();
>
Thanks for the answers. I wasn't aware of the fact that ob's could
nest. So one can manually translate the first try-catch to the second:
try {
// ... code
} catch (Exception $e) {
// ... code
}
ob_start();
try {
// ... code
ob_end_flush();
} catch (Exception $e) {
ob_end_clean();
// ... code
}
More verbose, but works.
--
Mehmet