|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I want to know what is the best solution for handling errors. After reading some documents dealing with the subject, i have three options: * Using a class for error handling * Using PEAR error object * Using try and catch exceptions The error handling i want to implement will be done in a big application that was developed from the beginning without any concern about error handling. Thank you __________________________________________________ __________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsea...egory=shopping |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
It Maq wrote:
> I want to know what is the best solution for handling errors. After > reading some documents dealing with the subject, i have three > options: > * Using a class for error handling No point IMO when you could use either the below two. > * Using PEAR error object I wouldn't advise it. > * Using try and catch exceptions In a new app, or (particularly) if you're adapting existing code, this is the one I'd recommend. > The error handling i want to implement will be done in a big > application that was developed from the beginning without any concern > about error handling. Aren't they all? :-/ -- Richard Heyes Employ me: http://www.phpguru.org/cv |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
> I want to know what is the best solution for handling errors. After reading some
> documents dealing with the subject, i have three options: > * Using a class for error handling > * Using PEAR error object > * Using try and catch exceptions > The error handling i want to implement will be done in a big application that was > developed from the beginning without any concern about error handling. It seems to me that 1 and 3 aren't necessarily mutually exclusive. I believe that you can use your own error classes in php's try/catch functionality. As for PEAR's error object, unless you are using PEAR elsewhere in your app I'm not sure it would be worthwhile to just use this very small piece. This is all just IMO. thnx, Chris |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
2008. 03. 12, szerda keltezéssel 07.18-kor It Maq ezt Ãrta:
> Hi, > > I want to know what is the best solution for handling errors. After reading some documents dealing with the subject, i have three options: > * Using a class for error handling > * Using PEAR error object > * Using try and catch exceptions I would go for try/catch, define different exception classes if different actions need to be taken, catch them based on their class to take appropriate action, and catch anything else in the top layer. greets, Zoltán Németh > > The error handling i want to implement will be done in a big application that was developed from the beginning without any concern about error handling. > > Thank you > > > > > __________________________________________________ __________________________________ > Looking for last minute shopping deals? > Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsea...egory=shopping |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
try / catch is the most versatile and has the advantage of giving you
a stack trace as well as being able to differentiate between different error types easily. This is a really cool feature of PHP5. Now, if you are using PEAR modules or some code that relies on trigger_error, you may want to customize how those errors are handled. For example: [MyScript.php] <?php require_once('ErrorHandler.php'); require_once('PearErrorHandler.php'); ErrorHandler::init(); PearErrorHandler::init(); ?> [ErrorHandler.php] <?php class ErrorHandler { static function init() { set_error_handler('ErrorHandlerProc'); } } function ErrorHandlerProc($errno, $errstr, $errfile, $errline) { if (!(error_reporting() & $errno)) { return; } $msg = "Error: $errstr in $errfile on line $errline."; throw new Exception($msg); } ?> [PearErrorHandler.php] <?php require_once('PEAR.php'); class PearErrorHandler { static function init() { PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'PearErrorHandlerProc'); } } function PearErrorHandlerProc($err) { $str = $err->getMessage() . ' (' . $err->getUserInfo() . ')'; throw new Exception($str); } ?> On Mar 12, 10:18 am, itmaqu...@yahoo.com (It Maq) wrote: > Hi, > > I want to know what is the best solution for handling errors. After reading some documents dealing with the subject, i have three options: > * Using a class for error handling > * Using PEAR error object > * Using try and catch exceptions > > The error handling i want to implement will be done in a big application that was developed from the beginning without any concern about error handling. > > Thank you > > __________________________________________________ __________________________________ > Looking for last minute shopping deals? > Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsea...egory=shopping |
|
![]() |
| Outils de la discussion | |
|
|