Tell me more ×  I know I can throw exception from constructor in
PHP but should I do it? For example, if a parameter's value is
not as I expected it.  Or should I defer throwing an exception
till a method is invoked. What are advantages and disadvantages
in both cases?  share|improve this question the question is do
you want your users to see ugly exception error messages? – 
Lawrence Cherone Feb 29 '12 at 10:57 @LawrenceCherone no, that's
not the question. Not at all. The question is whether to raise
an exception immediately when the ctor cannot set the object
into a valid state from the arguments passed to it or to defer
that until a method operating on that instance with possible
invalid state is called. Better suited for programmers though.
–  Gordon Feb 29 '12 at 11:00 add comment  migrated from Feb 29
'12 at 15:12  This question came from our site for professional
and enthusiast programmers.  5 Answers  up vote 31 down vote
accepted  Why would you postpone throwing the exception?  If you
know that the o