5/01/2017

PHP7 Error Reporting & Error Catching: Not showing errors

In earlier versions of PHP it was easy to see your errors. For the most part, whenever there was an error, it would just show up on the screen. Not very secure, but helpful.

You could control the various types of errors that would appear using:
error_reporting(E_ALL & ~E_NOTICE) -- which meant: Show me all of the errors, but don't show the less important notices.

In later versions you had the ability to use try-catch blocks.

The basic usage looked like this:

try {
   // DO MY CODE HERE;
}
catch (EXCEPTION $e) {
  echo $e->getMessage();
}

As of PHP7,  this method has changed a little bit. Instead of EXCEPTION, we use THROWABLE in PHP7. To also support servers still using PHP5, you can add an additional clause to catch errors using the legacy code:

try {
   // DO MY CODE HERE;
}
catch (THROWABLE $t) {
   echo $t->getMessage();
}
catch (EXCEPTION $e) {
   echo $e->getMessage();
}

2 comments :

  1. In the technical world, creating a first impression for the E-commerce store is the important thing for getting the customer hooked with the site. The post you have shared here is very informative and work on the areas we don’t consider.
    Hire Web Developer
    Hire wordpress developer India
    Hire a Programmer
    Mobile App Development India
    Hire Wordpress Developer

    ReplyDelete
  2. I’m impressed with the post which you have shared. This is very informative to know the benefits of outsourcing web development services.
    Wordpress Development Company
    Wordpress Theme Development
    Wordpress Web Development
    Wordpress Plugin Development
    Wordpress Development Services

    ReplyDelete