Earlier quoted context omitted.
> Don't throw exceptions if you can handle the error and continue where you left off. Exceptions is for when you can't continue. Yes, although quoting that example doesn't support the assertion. JSON.parse is a library function. How can it judge whether the caller can continue or not just because the JSON cannot be parsed? > Think of throwing as a way to roll back transaction, stop whatever you were trying to do, and…
> JSON.parse is a library function. How can it judge whether the caller can continue or not just because the JSON cannot be parsed? Don't make assumptions about the caller, throw if your library can't continue. > So although try/catch avoids the hassle of checking state after each operation, you pay for it on errors. If your language supports RAII ( http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initial... ) yo…
a = acquire(A);
if (!a) goto err_a;
b = acquire(B);
if (!b) goto err_b;
c = acquire(C);
if (!c) goto err_c;
do_stuff(a,b,c);
err_c:
release(b);
err_b:
release(a);
err_a:
return;
This is precisely why goto is not universally evil.