Application errors versus user errors in PHP

So, after long discussions back and forth, I came up with what, in my opinion, might be a valid plan for handling Application / System vs User Errors (Ie Validation Issues, Permission Issues, etc.) errors.

Application / system errors will be handled using a special error handler (via set_error_handler ()). Depending on the severity of the error, the user may be redirected to the general error page (Ie Fatal Error), or the error may simply be encrypted (i.e. E_WARNING).

These errors are most likely caused by problems outside user control (Missing file, Bad logic, etc.).

The second set of errors will be User Generated. These are those that cannot automatically cause an error, but will be considered as such. In these cases, I decided to use the trigger_error () function and, as a rule, cause a decrease or notification, which will be quietly registered by the error handler. After that, the developer will have to redirect the user to another page or display some more meaningful message for the user.

Thus, any type of error is always logged, but custom errors still allow the developer to freely handle it in their own way. That is, redirect them back to their form, filling them out completely and a message about what went wrong.

Does anyone see this as something wrong or have a more intuitive way? My approach to error handling, as a rule, has its own methods, but a way must be established.

+5
source share
1 answer

I really like exceptions over the old error handling . The benefits include:

  • You can postpone error handling: there is no need to make a decision (stop or continue, display a message or a log) at the very moment when an error occurs. This allows for cleaner code and cleaner output (you cannot always print a message when you make a fopen call).

  • . : , , .

  • , , ; UserNotAllowedException E_USER_ERROR.

.

+2

All Articles