Knowledgebase

Error Handling in PHP Print

  • phplaravel, php, errors, troubleshooting, guide, howto, solution, zillionkinghost
  • 0

Failing properly.

WHAT PHP PRODUCES

Errors, at several levels of severity Exceptions, which can be caught

WHAT TO SET IN DEVELOPMENT

Display errors on, and report everything.

WHAT TO SET IN PRODUCTION

Display errors off, and log everything.

WHY OFF

Errors displayed to visitors reveal paths, versions and sometimes credentials.

WHAT TO DO INSTEAD

Log them, and show a generic message.

WHAT TO CATCH

Specific exceptions you can actually handle.

WHAT NOT TO CATCH

Everything, indiscriminately.

WHY

It hides bugs you would want to know about.

WHAT TO DO WHEN YOU CANNOT HANDLE SOMETHING

Let it propagate, or throw something more meaningful.

WHAT TO NEVER DO

Suppress errors with the suppression operator.

WHY

It hides the problem without solving it, and makes diagnosis impossible.

WHAT TO ALWAYS CLEAN UP

Files, connections and locks, whether or not an error occurred.

WHAT TO LOG

What failed, with what input, and when.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot