<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":1144,"date":"2021-07-21T13:14:32","date_gmt":"2021-07-21T13:14:32","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=1144"},"modified":"2021-09-08T11:44:27","modified_gmt":"2021-09-08T11:44:27","slug":"explain-about-error-handling-in-php","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/","title":{"rendered":"Explain about error handling in php ?"},"content":{"rendered":"<div class=\"TextHeading\">\n<div class=\"hddn\">\n<h2 id=\"explain-about-error-handling-in-php\" class=\"color-pink\" style=\"text-align: justify;\">Explain about error handling in php ?<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>Error handling is the process of catching errors elevated from program and then taking correct action. If you would handle errors then the most common error checking methods given in PHP.\n<ul>\n<li>die() function<\/li>\n<li>Custom errors and error triggers<\/li>\n<li>Error reporting<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"die-function\" class=\"color-green\">die() function<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>To write the PHP program you should check all possible error condition before checking and take appropriate action when required.<\/li>\n<li>The following example without having \/tmp\/test.xt file and with this file.<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-php code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-php code-embed-code\">&lt;?php<br\/>   if(!file_exists(&quot;\/tmp\/test.txt&quot;)) {<br\/>      die(&quot;File not found&quot;);<br\/>   }else {<br\/>      $file = fopen(&quot;\/tmp\/test.txt&quot;,&quot;r&quot;);<br\/>      print &quot;Opend file sucessfully&quot;;<br\/>   }<br\/>   \/\/ Test of the code here.<br\/>?&gt;<\/code><\/pre> <\/div>\n<\/div>\n<\/div>\n<div class=\"CodeContent\" style=\"text-align: justify;\">\n<div class=\"hddn\"><\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"custom-errors-and-error-triggers\" class=\"color-green\">Custom errors and error triggers<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>We can write own function to handling any error. PHP provides a framework to define error handling function.<\/li>\n<li>This function must be able to handle a minimum of two parameters (error level and error message) but can accept up to five parameters (optionally: file, line-number, and the error context)<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"subheading\" style=\"text-align: justify;\">\n<h2 id=\"syntax\">Syntax<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-php code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-php code-embed-code\">error_function(error_level,error_message, error_file,error_line,error_context);<\/code><\/pre> <\/div>\n<\/div>\n<div class=\"TextHeading\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<h2 id=\"error-reporting\" class=\"color-green\">Error reporting<\/h2>\n<\/div>\n<\/div>\n<div class=\"Content\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<ul>\n<li>These error report levels are the different types of error the user-defined error handler can be used.<\/li>\n<li>The errors are .E_ERROR, E_WARNING, E_PARSE, E_NOTICE, E_CORE_ERROR, E_CORE_WARNING, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_STRICT, E_RECOVERABLE_ERROR, E_ALL<\/li>\n<li>These all errors handle to using set_error_handler function.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"CodeContent\" style=\"text-align: justify;\">\n<div class=\"hddn\">\n<figure class=\"highlight\"><div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-php code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-php code-embed-code\">&lt;?php<br\/>   error_reporting( E_ERROR );<br\/>   <br\/>   function handleError($errno, $errstr,$error_file,$error_line) {<br\/>      echo &quot;&lt;b&gt;Error:&lt;\/b&gt; [$errno] $errstr - $error_file:$error_line&quot;;<br\/>      echo &quot;&lt;br \/&gt;&quot;;<br\/>      echo &quot;Terminating PHP Script&quot;;<br\/>      <br\/>      die();<br\/>   }<br\/>   <br\/>   \/\/set error handler<br\/>   set_error_handler(&quot;handleError&quot;);<br\/>   <br\/>   \/\/trigger error<br\/>   myFunction();<br\/>?&gt;<\/code><\/pre> <\/div><\/figure>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Answer : Error handling is the process of catching errors&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[8182],"tags":[5432,8217,195,491,8233,7383,7352,199,214,198,5940,290,205,8218,8219,8220,8216,8234,8235,196,212,7677,5941,215,207,8214,204,8221,8236,8237,8222,8238,8223,8224,8239,8240,8241,8242,8225,8226,8243,8227,8228,8229,8230,8231,208,1744,8215,200,8232,197,284,280,216,15879],"class_list":["post-1144","post","type-post","status-publish","format-standard","hentry","category-php","tag-3i-infotech-limited-interview-questions-and-answers","tag-accel-frontline-ltd-interview-questions-and-answers","tag-accenture-interview-questions-and-answers","tag-applied-materials-interview-questions-and-answers","tag-basic-php-errors-or-problems","tag-brillio-technologies-pvt-ltd-interview-questions-and-answers","tag-cactus-communications-interview-questions-and-answers","tag-casting-networks-india-pvt-limited-interview-questions-and-answers","tag-cgi-group-inc-interview-questions-and-answers","tag-chetu-interview-questions-and-answers","tag-csg-international-interview-questions-and-answers","tag-cybage-interview-questions-and-answers","tag-dell-international-services-india-pvt-ltd-interview-questions-and-answers","tag-disable-warning-in-php-ini","tag-error-handling-in-php","tag-error-reporting-php-inierror_reporting0-not-working","tag-harbinger-systems-interview-questions-and-answers","tag-how-to-display-an-error-message-on-the-form-using-php","tag-how-to-display-error-message-in-html-using-php","tag-ibm-interview-questions-and-answers","tag-indecomm-global-services-interview-questions-and-answers","tag-info-edge-interview-questions-and-answers","tag-infogain-interview-questions-and-answers","tag-maintec-technologies-pvt-ltd-interview-questions-and-answers","tag-mphasis-interview-questions-and-answers","tag-net-solutions-interview-questions-and-answers","tag-oracle-corporation-interview-questions-and-answers","tag-php-7-not-showing-errorsphp-display_errors","tag-php-display_errors","tag-php-error-and-exception-handling","tag-php-error-handling","tag-php-error-handling-and-logging","tag-php-error-handling-best-practices","tag-php-error-handling-try-catch","tag-php-error-handling-tutorial","tag-php-error-meaning","tag-php-error-message","tag-php-error-message-display","tag-php-error-messagephp-error-message-display","tag-php-error-reporting-not-working","tag-php-error","tag-php-errorphp-hide-errors","tag-php-mysql-error-handling","tag-php-startup-error","tag-php-try-catch-fatal-error","tag-php-ini-display_errors","tag-prokarma-softech-pvt-ltd-interview-questions-and-answers","tag-raqmiyat-information-technologies-pvt-ltd-interview-questions-and-answers","tag-sopra-steria-interview-questions-and-answers","tag-tech-mahindra-interview-questions-and-answers","tag-types-of-error-in-php","tag-unitedhealth-group-interview-questions-and-answers","tag-valuelabs-interview-questions-and-answers","tag-virtusa-consulting-services-pvt-ltd-interview-questions-and-answers","tag-wipro-interview-questions-and-answers","tag-yahoo-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Explain about error handling in php ? - PHP Interview Questions -Wikitechy<\/title>\n<meta name=\"description\" content=\"Explain about error handling in php ? - Error handling is the process of catching errors elevated from program and then taking correct action.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Explain about error handling in php ? - PHP Interview Questions -Wikitechy\" \/>\n<meta property=\"og:description\" content=\"Explain about error handling in php ? - Error handling is the process of catching errors elevated from program and then taking correct action.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-21T13:14:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-08T11:44:27+00:00\" \/>\n<meta name=\"author\" content=\"Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/\",\"name\":\"Explain about error handling in php ? - PHP Interview Questions -Wikitechy\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"datePublished\":\"2021-07-21T13:14:32+00:00\",\"dateModified\":\"2021-09-08T11:44:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\"},\"description\":\"Explain about error handling in php ? - Error handling is the process of catching errors elevated from program and then taking correct action.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757\",\"name\":\"Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g\",\"caption\":\"Editor\"},\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Explain about error handling in php ? - PHP Interview Questions -Wikitechy","description":"Explain about error handling in php ? - Error handling is the process of catching errors elevated from program and then taking correct action.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/","og_locale":"en_US","og_type":"article","og_title":"Explain about error handling in php ? - PHP Interview Questions -Wikitechy","og_description":"Explain about error handling in php ? - Error handling is the process of catching errors elevated from program and then taking correct action.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/","og_site_name":"Wikitechy","article_published_time":"2021-07-21T13:14:32+00:00","article_modified_time":"2021-09-08T11:44:27+00:00","author":"Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Editor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/","name":"Explain about error handling in php ? - PHP Interview Questions -Wikitechy","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"datePublished":"2021-07-21T13:14:32+00:00","dateModified":"2021-09-08T11:44:27+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757"},"description":"Explain about error handling in php ? - Error handling is the process of catching errors elevated from program and then taking correct action.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/php\/explain-about-error-handling-in-php\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/4d5a581fb5470d1560324bddc5e8b757","name":"Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9531079fe7e07841b7b156c04d65e5f39d4adfd18b6ffe3edfff8ca5aab85b5?s=96&d=mm&r=g","caption":"Editor"},"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/editor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/1144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=1144"}],"version-history":[{"count":3,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/1144\/revisions"}],"predecessor-version":[{"id":3045,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/1144\/revisions\/3045"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=1144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=1144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=1144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}