Reply to Re: Error Trapping Within Classes

Your name:

Reply:


Posted by ZeldorBlat on 09/19/06 17:53

47computers@gmail.com wrote:
> > Look at trigger_error()
> > <http://www.php.net/trigger_error>
> >
> > But you may really want to be using exceptions for the case described
> > above.
>
> This has definitely sent me in the right direction, thank you :)
>
> Hopefully one last question: Suppose I enclose my function's code
> within a try/catch. When I want to manually error out, I throw a new
> Exception with the error message I want. From a design perspective,
> what _should_ I be doing in that catch block?
>
> Currently, for my testing, I'm just calling trigger_error in the catch
> block to execute my custom error handler which is working like a charm.
> Is this bad form in any way? This may be a silly question, but I
> figure it's worth asking.
>
>
> -David

The beauty of exceptions is that if you want to handle them you can, or
you can let someone else handle them, or you can not handle them at
all. Furthermore, you can decide what to do with it based on some sort
of condition. So, for example you might say:

try {
//do something that might throw an exception with code = 1
//do something that might throw an exception with code = 2
} catch (Exception $e) {
if($e->getCode() == 1) {
//I will gracefully handle the exception when the code is 1
}
else {
throw $e; //let someone else deal with it
}
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация