note 85646 added to class.errorexception

From: Date: Wed, 10 Sep 2008 13:08:13 +0000
Subject: note 85646 added to class.errorexception
Groups: php.notes 
Request: Send a blank email to php-notes+get-144290@lists.php.net to get a copy of this message
Building upon the notes present, here is a set of functions that transforms the error into an exception and reports the error to screen / log depending upon the PHP ini settings. //Begin helper function definition function ReportError ($msg) { // be sure that the supplied parameter is a string and not empty if (empty ($msg) || !is_string ($msg)) { throw new ErrorException ('Invalid parameter supplied to ReportError', 0, E_ERROR); } // retrieve error settings $display = strtolower (ini_get ('display_errors')); $log = strtolower (ini_get ('log_errors')); // check if we're displaying errors if ($display === 'on' || $display === '1' || $display === 1 || $display === 'true' || $display === true) { echo $msg; } // check if we're logging errors if ($log === 'on' || $log === '1' || $log === 1 || $log === 'true' || $log === true) { $result = error_log ($msg); // check for error while logging if (!$result) { throw new ErrorException ('Attempt to write message to error log failed in ReportError', 0, E_ERROR); } } } //Begin main function definition function ErrorsAsExceptions ($level, $msg, $fileName, $lineNumber) { // do nothing if error reporting is turned off if (error_reporting () === 0) { return; } // be sure received error is supposed to be reported if (error_reporting () & $level) { try { // report error to appropriate channels ReportError ($reportMsg); } catch (ErrorException $e) { // ignore errors while reporting } // go ahead and throw the exception throw new ErrorException ($msg, 0, $level, $fileName, $lineNumber); } } ---- Server IP: 209.41.74.194 Probable Submitter: 74.203.156.126 ---- Manual Page -- http://www.php.net/manual/en/class.errorexception.php Edit -- https://master.php.net/note/edit/85646 Del: integrated -- https://master.php.net/note/delete/85646/integrated Del: useless -- https://master.php.net/note/delete/85646/useless Del: bad code -- https://master.php.net/note/delete/85646/bad+code Del: spam -- https://master.php.net/note/delete/85646/spam Del: non-english -- https://master.php.net/note/delete/85646/non-english Del: in docs -- https://master.php.net/note/delete/85646/in+docs Del: other reasons-- https://master.php.net/note/delete/85646 Reject -- https://master.php.net/note/reject/85646 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144290) next »