Throw Exceptions from setters: second opinion



Hi all,

Recently somebody on a forum told me, and nearly convinced me, that throwing Exceptions from setters is bad practice. He stated that setters should only return boolean false if the provided input is not valid, since that is what they are expected to do: validate input and simply tell wheter it's valid or not. Furthermore he stated that throwing Exceptions is only meaningful when an internal routine of the class encounters invalid data. Does this sound reasonable to you? I'm not sure yet myself. Love to hear your opinions on the matter.

Thanks in advace.
.



Relevant Pages

  • Re: Throw Exceptions from setters: second opinion
    ... Recently somebody on a forum told me, and nearly convinced me, that throwing Exceptions from setters is bad practice. ... He stated that setters should only return boolean false if the provided input is not valid, since that is what they are expected to do: validate input and simply tell wheter it's valid or not. ... Furthermore he stated that throwing Exceptions is only meaningful when an internal routine of the class encounters invalid data. ...
    (comp.lang.php)
  • Re: Throw Exceptions from setters: second opinion
    ... He stated that setters should only return boolean false if the provided input is not valid, since that is what they are expected to do: validate input and simply tell wheter it's valid or not. ... Furthermore he stated that throwing Exceptions is only meaningful when an internal routine of the class encounters invalid data. ... // act on return value false of tellMyObjectToTakeAction ...
    (comp.lang.php)
  • Re: Throw Exceptions from setters: second opinion
    ... He stated that setters should only return boolean false if the provided input is not valid, since that is what they are expected to do: validate input and simply tell wheter it's valid or not. ... Furthermore he stated that throwing Exceptions is only meaningful when an internal routine of the class encounters invalid data. ... // act on return value false of tellMyObjectToTakeAction ...
    (comp.lang.php)
  • Re: Throw Exceptions from setters: second opinion
    ... He stated that setters should only return boolean false if the provided input is not valid, since that is what they are expected to do: validate input and simply tell wheter it's valid or not. ... Furthermore he stated that throwing Exceptions is only meaningful when an internal routine of the class encounters invalid data. ... // act on return value false of tellMyObjectToTakeAction ...
    (comp.lang.php)
  • Re: Throw Exceptions from setters: second opinion
    ... He stated that setters should only return boolean false if the provided input is not valid, since that is what they are expected to do: validate input and simply tell wheter it's valid or not. ... Furthermore he stated that throwing Exceptions is only meaningful when an internal routine of the class encounters invalid data. ... That way you can chain operations. ... // act on return value false of tellMyObjectToTakeAction ...
    (comp.lang.php)