You are here: Re: do professional PHP programmers use error checking in their code? « PHP Programming Language « IT news, forums, messages
Re: do professional PHP programmers use error checking in their code?

Posted by Benjamin Esham on 09/03/06 02:52

lawrence k wrote:

> [should I write my own error checking?]

I believe other posters have given pretty firm answers to that... let me
just make a suggestion in the name of readability.

Instead of writing

if ( ! $thereIsAnError ) {
...
if ( ! $thereIsAnotherError ) {
...
} else {
// handle the second problem
} else {
// handle the first problem
}

use

if ($thereIsAnError)
handle_error($thereIsAnError);
...

As you can see, this puts the error checking first in the file, and it also
prevents the unholy levels of if/else nesting that can occur if you use
if/else blocks for all of your error checking. Assuming that handle_error()
will exit, you can just add a quick, two-line test to check for and handle
an error; there's no need to wrap the entire rest of the code in an else { }
block.

HTH,
--
Benjamin D. Esham
bdesham@gmail.com | AIM: bdesham128 | Jabber: same as e-mail
'I wish I had never come here, and I don't want to see no more
magic,' he said and fell silent.
— Sam in /The Fellowship of the Ring/

 

Navigation:

[Reply to this 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

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