Php Pear Error Handling
Contents |
E_STRICT-compatible code (Previous) Best practices pear::iserror (Next) PEAR Manual Coding Standards Indenting and
Php Exception Best Practices
LineLength Control Structures Function Calls Class Definitions Function Definitions Arrays Comments Including
Pear_error
Code PHP Code Tags Header Comment Blocks Using SVN Example URLs Naming Conventions File Formats E_STRICT-compatible code Error HandlingGuidelines
Php Error Handling
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 php exceptions 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 /* set a shutdown function for static classes (package developer related) (Previous) Create a new PEAR_Error object and optionally specify error-handling instructions (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::isError() PEAR::isError() – checks for a https://pear.php.net/manual/en/standards.errors.php PEAR_Error object Synopsis require_once 'PEAR.php'; boolean PEAR::isError ( mixed $data , mixed $msgcode ) Description isError() examines whether a variable is a PEAR_Error object and - optional - contains a specific error message or code. Parameter mixed $data https://pear.php.net/manual/en/core.pear.pear.iserror.php variable to check mixed $msgcode additional error message or error code to check Return value mixed - returns TRUE, if the variable was a PEAR_Error and, if given, contains $msgcode set a shutdown function for static classes (package developer related) (Previous) Create a new PEAR_Error object and optionally specify error-handling instructions (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 checks for a PEAR_Error object (Previous) sets handling of errors generated through PEAR packages (Next) PEAR https://pear.php.net/manual/en/core.pear.pear.raiseerror.php Manual PEAR Introduction Constants PEAR::PEAR() PEAR::_PEAR() PEAR::getStaticProperty() PEAR::registerShutdownFunc() PEAR::isError() PEAR::raiseError() http://pear.php.net/support/effectivepearuse.php 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 $options , mixed $userinfo , error handling 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 simplest errors, in order to simplify error handling and php pear error 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 - it will not work. Return value A PEAR_Error object is returned, unless PEAR_ERROR_DIE terminates execution or a PEAR_ERROR_EXCEP Books Tutorials Presentation Slides Icons Forums Developing Effectively with PEAR Packages by Justin Patrin, edited by Gregory Beaver Introduction This document is the result of years of collected helpful hints that everyone using PEAR packages should know about. Users who come on IRC often need to know this information, and so now this knowledge is available for all to learn from. Error Handling Most PEAR packages will return errors from a function call. These errors take the form of PEAR_Error objects. The correct way to handle these is:
*ConnecttoSpecifiedDatabase
*
*@throwsExample_Datasource_Exceptionwhenitcan'tconnect
*tospecifiedDSN.
*/
functionconnectDB($dsn)
{
$this->db=&DB::connect($dsn);
if(DB::
require_once'PEAR/DB.php';
$db=DB::connect($dsn);
if(PEAR::isError($db)){
//Thisisanexampleofwhatyoucandowhenanerrorhappens.Youcouldalsologtheerrorortrytorecoverfromit.
die($db->getMessage().''.print_r($db