On 08/10/13 06:45, Brion Vibber wrote:
> Out of curiosity, what's an actual example of code where the execution flow
> of exceptions is significantly more surprising than the execution flow of a
> billion manual checks to avoid "Fatal error: Call to a member function
> foo() on a non-object"?
> 
> I've heard the vague claim that exceptions are confusing for years, but for
> the life of me I've never seen exception-handling code that looked more
> complex or confusing than code riddled with checks for magic return values.

I don't think exceptions are confusing. The sole difference between
exceptions and error returns is their default handling -- exceptions
unwind the stack and show an error to the user, whereas error returns
do nothing.

Sometimes it is a choice between exception and a fatal error, but more
often, it is a choice between an exception and some subtle
context-dependent malfunction. In many cases, ignoring the error is
not exactly correct, but it is less damaging than allowing the
exception to terminate the whole request so that it is shown to the
user. Whether you prefer a subtle failure or an epic failure is mostly
a matter of personal preference.

The designers of PHP have their feet firmly in the "subtle failure"
camp, and this presumably influences the developers who work with the
language. Personally, I am inclined towards tolerance -- I think
developers are most happy and productive when they are allowed to
choose which approach they will take to this sort of problem.

Of course, that doesn't stop us from offering advice.

-- Tim Starling


_______________________________________________
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to