Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9186215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:28:12+00:00 2026-06-17T19:28:12+00:00

During the process of my PHP learning I have been trying to read up

  • 0

During the process of my PHP learning I have been trying to read up on the best practices for error reporting and handling, but statements vary person to person and I have struggled to come up with a clear concise way of handling errors in my applications. I use exceptions on things that could go wrong, but for the most part it is hard for me to understand whether an exception should kill the application and display an error page or just be caught and silently dealt with.

Something that seems to elude me is, is there such thing as too much reporting? Every single time you call a function something could go horribly wrong meaning that if you were to confirm every single function call you would have to fill pages with if statements and work out what effect one failure may have on the rest. Is there a concise document or idea for error reporting that could clear this up for me? Are there best practices? What are the best examples of good error handling?

Currently I do the following:

  • Add important event results to an array to be logged and emailed to me if a fatal error was to occur
  • Display abstract/generic errors for fatal errors.
  • Use exceptions for cases that are likely to fail
  • Turn on error reporting in a development environment and off for live environment
  • Validate all user input data
  • Sanitizing invalid user input
  • Display concise, informative error messages to users without providing a platform for exploitation.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:28:13+00:00Added an answer on June 17, 2026 at 7:28 pm

    Exceptions are the only thing that you haven’t understood IMHO: exceptions are meant to be out of your control, are meant to be caught be dealt with from outside the scope they are thrown in. The try block has a specific limit: it should contain related actions. For example take a database try catch block:

    $array = array();
    try {
        // connect throws exception on fail
        // query throws exception on fail
        // fetch results into $array
    } catch (...) {
        $array[0]['default'] = 'me';
        $array[0]['default2'] = ...;
        ...
    }
    

    as you can see I put every database related function inside the try block. If the connection fails the query and the fetching is not performed because they would have no sense without a connection. If the querying fails the fetching is skipped because there would be no sense in fetching no results. And if anything goes wrong, I have an empty $array to deal with: so I can, for example, populate it with default data.

    Using exceptions like:

    $array = array();
    try {
        if (!file_exists('file.php')) throw new Exception('file does not exists');
        include('file.php');
    } catch (Exception $e) {
        trigger_error($e->getMessage());
    }
    

    makes no sense. It just a longer version of:

    if (!file_exists('file.php')) trigger_error('file does not exists');
        include('file.php');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

During the process of building software applications, you would start testing what you have
i have application who use specific process during running and i want to sample
I'm trying to combine all javascript files in a project during the build process,
During debug process, I noticed that script dies on $stmt->fetch() or die($stmt->error); line. There
During the process of trying to develop an checkbox activated mySQL query based on
I have a problem, I use pcntl_fork to fork a process in PHP, $pid
I am trying to redeploy a Symfony 2.1x project I have been working on
I'm posting HTML content via AJAX to PHP. During debugging process i see that
hello am trying to learn ftp file transfer in php. i have done all
During compilation process many errors are thrown on the screen. To start resolving them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.