Pear Error Handling
Contents |
E_STRICT-compatible code (Previous) Best pear::iserror practices (Next) PEAR Manual Coding Standards Indenting
Php Exception Handling Best Practices
and LineLength Control Structures Function Calls Class Definitions Function Definitions Arrays Comments
Php Error Handling
Including Code PHP Code Tags Header Comment Blocks Using SVN Example 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 /* Constants defined in and used by PEAR_ErrorStack (Previous) add user information (Next) PEAR Manual PEAR base classes PEAR base and errorhandling class PEAR_Exception PEAR_ErrorStack PEAR Error object System PEAR_Error [deprecated] Table of Contents PEAR_Error::addUserInfo() — add user information PEAR_Error::getCallback() — get callback function name PEAR_Error::getCode() — get error code PEAR_Error::getMessage() — get error message PEAR_Error::getMode() — get error mode PEAR_Error::getDebugInfo() — get debug information PEAR_Error::getType() https://pear.php.net/manual/en/standards.errors.php — 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 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() https://pear.php.net/manual/en/core.pear.pear-error.php 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 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() https://pear.php.net/manual/en/core.pear.pear.raiseerror.php 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 $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 error handling $code Error code. It is recommended to use an error code for even the 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 pear error handling $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 - it will not work. Return value A PEAR_Error object is returned, unless PEAR_ERROR_DIE terminates execution or a PEAR_ERROR_EXCEPTION is never handled. checks for a PEAR_Error object (Previous) sets handling of errors generated through PEAR packages (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: There are no user contributed notes for this page. PRIVACY POLICY|CREDITS Copyright © 2001-2016 The PHP Group All rights reserved. Bandwidth and hardware provided by: eUKhost
*ConnecttoSpecifiedDatabase
*
*@throwsExample_Datasource_Exceptionwhenitcan'tconnect
*tospecifiedDSN.
*/
functionconnectDB($dsn)
{
$this->db=&DB::connect($dsn);
if(
{
protected$_type;
protected$_userInfo;
functiongetType()
{
return$this->_type;
}
functiongetDebugInfo()
{
return$this->getUserInfo();
}
functiongetUserInfo<