Try and Catch et gestion des exceptions
Par Ronan le vendredi, juin 30 2006, 23:14 - PHP 5 / PHP 6 - Lien permanent
Je note pour mémoire une citation tirée de "PHP 5 Power Programming" de Andi Gutmans, Stig Sæther Bakken et Derick Rethans :
When using exceptions, follow these basic rules (both for performance and code-manageability reasons):
- Remember that exceptions are exceptions. You should only use them to handle problems, which brings us to the next rule….
- Never use exceptions for flow control. This makes the code hard to follow (similar to the goto statement found in some languages) and is slow.
- The exception should only contain the error information and shouldn't contain parameters (or additional information) that affect flow control and logic inside the catch handler.
Ca s'applique finallement aussi bien à PHP5 qu'à .NET ou Java.
J'ajoute 2-3 liens :
- Exceptions in PHP 5 chez Zend.com
- PHP 5 et les exceptions : utiliser et étendre (chez classes.scriptsphp.org)
- La classe Extension de PHP 5 : utiliser et étendre (chez php.net)
Le livre "PHP 5 Power Programming" a été publié en Open Publication License, v1.0
Commentaires