|
Posted by www.douglassdavis.com on 09/16/05 18:40
Chung Leong wrote:
> www.douglassdavis.com wrote:
> > Let's say an invalid string is passed to construct it. What is the
> > appropriate way to handle this? I know in Java I would probably throw
> > an exception, but I don't know how much people really use exceptions in
> > PHP right now. So, I don't want to depend on it.
>
> That sounds like a programmer's error to me. The appropriate way to
> handle this to be to let the programmer know that he/she made a
> mistake. I would use trigger_error() or simply die().
>
> Call me old school. In my opinion things that are within a programmer's
> control are not exceptions.
I understand your perpective, but IMO there's 2 broad categories,
system exceptions, and then those things that the user of the library
does wrong, for example NumberFormatException in Java. The exception in
my library would be almost identical to a NumberFormatException.
Also, it may not be the programmer, but the end user that made the
mistake. For example, typing 5.5 in a field that only accepts
integers.
the user could validate it before making the object, but then again,
that could be part of the object's job.
--
http://www.douglassdavis.com
Navigation:
[Reply to this message]
|