|
Posted by Dikkie Dik on 09/16/05 20:50
I use exceptions in the same fashion as I would do in java and it works
just fine. For any untrapped exceptions, you can use an exception
handler function that can be registered with the set_exception_handler
command. With my pages, the error is written to an error log file, so I
can see what went wrong (and where) afterwards.
As for "the appropriate way", I use to check every non-private
parameter. But type hinting removes a lot of the necessity for checks.
Best regards
www.douglassdavis.com wrote:
> lets say i have a class
>
>
> class Thing
> {
> function __construct($string)
> {
> // initialize by string
> }
> }
>
>
> 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.
>
> What would be the appropriate way to handle this type of situation? I
> was thinking of two options
>
> 1. A ThingFactory that just returns null if the Thing couldn't be
> instantiated.
>
> 2. Remove the constructor and just have an initThing($string) method
> that returns false when something goes wrong.
>
> What would be appropriate here?
>
> --
> http://www.douglassdavis.com
>
[Back to original message]
|