Pear Set Error Handling
E_STRICT-compatible code (Previous) Best practices (Next) PEAR Manual Coding Standards Indenting pear::iserror and LineLength Control Structures Function Calls Class Definitions Function php exception handling best practices Definitions Arrays Comments Including Code PHP Code Tags Header Comment Blocks Using SVN Example php error handling URLs Naming Conventions File Formats E_STRICT-compatible code Error HandlingGuidelines Best practices Sample File (includingDocblock Commentstandards) The PEAR toolbox Error Handling Guidelines This part of the Coding Standards describes how errors are handled in PEAR packages that are developed for PHP 5 and 6. It uses Exceptions, introduced in PHP 5.0 with Zend Engine 2, as the error handling mechanism. Definition of an error An error is defined as an unexpected, invalid program state from which it is impossible to recover. For the sake of definition, recovery scope is defined as the method scope. Incomplete recovery is considered a recovery. One pretty straightforward example for an error /*
*ConnecttoSpecifiedDatabase
*
*@throwsExample_Datasource_Exceptionwhenitcan'tconnect
*tospecifiedDSN.
*/
functionconnectDB($dsn)
{
$this->db=&DB::connect($dsn);
if(DB::isError($this->db)){
thrownewExample_Datasource_Exception(
"Unabletoconnectto$dsn:".$this->db->getMessage()
);
checks for a PEAR_Error object (Previous) sets handling of errors generated through PEAR packages (Next) PEAR Manual PEAR Introduction Constants PEAR::PEAR() PEAR::_PEAR() PEAR::getStaticProperty() PEAR::registerShutdownFunc() PEAR::isError() PEAR::raiseError() PEAR::setErrorHandling() PEAR::expectError() PEAR::popExpect() PEAR::loadExtension() PEAR::raiseError() PEAR::raiseError() – Create a new PEAR_Error object and optionally specify error-handling instructions Synopsis require_once 'PEAR.php'; PEAR_Error PEAR::raiseError ( mixed $message , int $code , int $mode , int|array https://pear.php.net/manual/en/standards.errors.php $options , mixed $userinfo , string $error_class , boolean $skipmsg ) Description raiseError() Parameter string $message Error message string or PEAR_Error object. The default message is unknown error if left blank. integer $code Error code. It is recommended to use an error code for even the https://pear.php.net/manual/en/core.pear.pear.raiseerror.php simplest errors, in order to simplify error handling and processing. integer $mode Error mode. This is one of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, PEAR_ERROR_CALLBACK, or PEAR_ERROR_EXCEPTION. See setErrorHandling() for detailed information and examples of the meaning of these constants. mixed $options Error options. This depends on the value of $mode, and is documented in setErrorHandling(). mixed $userinfo Optional user information. This can be used to store any error-specific information, and has an unspecified format. string $error_class Error class name to use as the error object. The default error class is PEAR_Error. Use this parameter to specify another class to use, such as a custom class extending PEAR_Error boolean $skipmsg Use this parameter if you are using a custom class that does not accept an error message in its constructor. Never use this parameter without the $error_class parameter - i
Constants defined in and used by PEAR_ErrorStack (Previous) https://pear.php.net/manual/en/core.pear.pear-error.php add user information (Next) PEAR Manual PEAR base classes PEAR base and errorhandling class PEAR_Exception PEAR_ErrorStack PEAR Error object System https://pear.php.net/manual/en/core.pear.pear-errorstack.php PEAR_Error [deprecated] Table of Contents PEAR_Error::addUserInfo() — add user information PEAR_Error::getCallback() — get callback function name PEAR_Error::getCode() — get error error handling code PEAR_Error::getMessage() — get error message PEAR_Error::getMode() — get error mode PEAR_Error::getDebugInfo() — get debug information PEAR_Error::getType() — get error type PEAR_Error::getUserInfo() — get additional user-supplied information PEAR_Error::PEAR_Error() — constructor PEAR_Error::toString() — make string representation PEAR_Error is an object created by pear set error every function in PEAR in case of a failure. It provides information on why a function fails. How you get the object depends on PEAR::SetErrorHandling() Constants defined in and used by PEAR_ErrorStack (Previous) add user information (Next) Last updated: Sun, 23 Oct 2016 — Download Documentation Do you think that something on this page is wrong? Please file a bug report or add a note. View this page in: English User Notes: Note by: anrdaemon@freemail.ru 2008-09-01 20:11 UTC Who want actual exceptions support to packages like MDB2, try this: classePearErrorextendsException
{
protected$_type;
protected$_userInfo