Usually a PHP application has an user interface. In a MVC layered application you might throw some exceptions.
What type of message do you set in the exception:
A)
- a custom message to display to the user
- and you log the error with technical details before throwing it
B)
- a custom technical error and a custom exception
- no logging near the exception
- catch the exception, log the error and display a custom user message based on exception type
C) other variants
General Practice
C – You should only record backtrace when error happens, because you won’t be able to recover it. You catch error message inside your Application class and then depending on the setting either display message or log it and display some sort of generic screen to the user.
When logging error, add more information such as browser version, ip address, URL requested.
User-friendly messages
Inside my Models I sometimes throw “ForUser” type exceptions. Those don’t record backtrace and when caught by the Application class they are displayed to the user. There are few exception sub-classes to that such as Validation, Logic etc.
Re-Throwing exceptions
Some UI elements detect exceptions to properly display them, such as form submission would call Model->update(), catches validation exceptions and shows them for appropriate field inside my Ajax form.