Re: Clean error page without output buffering

[email protected] (Ashley Sheridan)
Newsgroups php.general
Message-ID <[email protected]>
On 19/10/2021 21:52, [email protected] wrote:
>
> Normally an error in the output generating code, whether generated 
> with a template engine or just by using PHP as the template engine 
> (which is what I do), will display AFTER any prior output has already 
> reached the browser.
>
> Is it possible to make a custom error and exception handler display a 
> clean page with a custom message without the use of output buffering?
>
>
Yes, you can wrap those parts of code that _might_ cause errors in a 
try/catch block. From there, you can do whatever you like with the 
thrown exception. Typically, the errors will still be logged to the 
error log, but you can determine how you would like to handle any 
problems, such as generating null objects rather than the one you 
intended to create, or just show a custom error message to the user.

-- 
Ashley Sheridan
https://www.ashleysheridan.co.uk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.