Home
Accueil
Downloads
Téléchargements
Forums
Forums
Your Account
Votre compte
Menu
· Accueil ·

· Communication ·
  · Forums
  · Messages privés
  · Contactez nous
  · Recommendez nous
  · Sondages
  · Les projets

· Nouvelles ·Stats
  · Sujets
  · Ecrire un article
  · Articles archivés
  · Articles RSS
  · Lettre de sécurité
  · Archive de lettres

· Téléchargements ·
  · Accueil
  · Nouveautés
  · Mises à jour
  · Thêmes

· Outils ·
  · Outils divers
  · Convertisseur de temps
  · Table de caractères
  · Générateur de boutons
  · Compresseur Javascript

· Documentation ·
  · Wiki
  · Questions/Réponses
  · Documents
  · Manuel PHP-Nuke
  · Manuel PHP
  · Manuel PEAR
  · Encyclopédies

· Liens ·
  · Nos liens
  · Nos fluxs RSS
  · Partenaires
  · Votre publicité
  · Sitemap
  · Mes bannières

· Infos ·
  · Rechercher
  · Votre compte
  · Liste des membres
  · Carte des membres
  · Top

· Divers ·
  · Météo
  · Galeries
  · Statistiques Phpnuke
  · MS Analysis


Using PEAR_Exception for advanced error handling in PHP 5+

Using PEAR_Exception for advanced error handling in PHP 5+

Using PEAR_Exception for advanced error handling in PHP 5+  --  Using PEAR_Exception

Introduction

This class is available as part of the PEAR package. Features include:

  • Nestable exceptions (
    <?php throw new PEAR_Exception($msg, $prev_exception); ?>
    )

  • Subject/Observer pattern, triggered when an exception is instantiated

  • Clear, detailed and attractively formatted error messages

  • Extra context information available compared to built-in Exception. For instance, a cause of the exception (PEAR_Error/PEAR_ErrorStack/another Exception).

  • Exception cause can be a PEAR_Error object, PEAR_Exception object or an array of mixed PEAR_Exceptions/PEAR_ErrorStack warnings

  • callbacks for specific exception classes and their children

Usage example:
<?php
require_once 'PEAR/Exception.php';

class Test {
	function foo() {
		throw new PEAR_Exception('Error Message', ERROR_CODE);
    }
}

function myLogger($pear_exception) {
    echo $pear_exception->getMessage();
}
// each time a exception is thrown the 'myLogger' will be called
// (its use is completely optional)
PEAR_Exception::addObserver('myLogger');
$test = new Test;
try {
    $test->foo();
} catch (PEAR_Exception $e) {
    print $e;
}
?>

API documentation is documented in the documentation for the PEAR package generated by phpDocumentor. The class is very simple, examine the source in the PEAR package to get a better idea of how it works.


Manuel PEAR pour PHP-Nuke © www.stefvar.com
Syndiquez notre contenu RSS, Atom, etc..
PHP-Nuke © 2007Reproduction interdite sans autorisation de ma part www.stefvar.com Copyright © 2008Thème iCGstation
Site français de la communauté PragmaMx