Reply to Re: Exception : an ugly grammer in programming

Your name:

Reply:


Posted by Willem Bogaerts on 07/17/07 10:56

> Well, friend. Yes, I'm doing PHP. But exception is a traditional
> machinism in programming languages. I'm very doubt about this.
> In procedure language, we return error code when we meet an error. So
> we need to design error code table and judge them in several
> statements. Finally they become boring.
> But how about use exception in OOP? Did we drop all "return error
> code" styles?

<snip>

> // so what can i do, if i want the fetchPage procedure go on fetching
> when SlowNetSpeed Exception happen?

I think you'll have to decide. Is it something that can be repaired from
outside the object? if so, you can throw an exception. Is it not broken
at all? Then it is not an exception. You could implement an event
mechanism (java style) to handle this events and just continue fetching.

The way I see it, it is the responsibility of the fetcher class to fetch
the page and inform the user if it can take a while. Not being able to
perform that task is an exception, but a slow connection is not.

So I would do something like:

class ConnectionNotifier
{public function NotifySlowConnection()
{echo 'Please have patience. It is rather busy at the moment.';}
}

class PageFetcher
{private $_slowConnectionWarner;
public function __construct(ConnectionNotifier $slowConnectionWarner)
{$this->_slowConnectionWarner = $slowConnectionWarner;}
public function FetchPage($URL)
{$connection = ... // establish a connection here
if(! $connection):
throw new NoPageException();
endif;
// if you notice a slow connection, withing a fetching loop:
$this->_slowConnectionWarner->NotifySlowConnection();
}
}

Off course, you would add code to make sure there is only one
notification, but you could do that in the ConnectionNotifier class to
keep the code clean.

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/

[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

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