On Jul 30, 4:51 pm, Zsolt Vasvari <[email protected]> wrote:
> By the way, the whole JSONException stuff is foobar-ed:
>
> There is a way to avoid JSONException to be thrown by using the opt*
> methods for reads, which I am doing now as I know that I created the
> data and it must be there.  But, there is no way to avoid catching the
> JSONException on put* operations as it will check the arguments to be
> NULL's and if they are, it throws the JSONException instead of just a
> NPE.

Right, and this is kind of my point.  The gap between checked/
unchecked exceptions themselves are not the problem.  It's the abuse
of the system that's the problem.  Wrapping a NPE inside a checked
exception is subverting the purpose of an unchecked NPE, specifically,
to point out a programmer error.

You said in your last post that you're "Not sure how the system
implements that, it may save it to a file, I don't know, I don't
care."  I think this abuse of the exception system has got you
confused about which exceptions you need to catch and which not.
These abuses are giving checked exceptions a bad name.

Suggesting that checked suggestions should be banned is, to me, kind
of like saying that prohibition of alcohol is a good idea because it
keeps people from doing stupid things after they abuse the substance.
People are always going to do stupid stuff in their software if
they're not disciplined or understand how things can best work.

Checked exceptions have their place in the world, and it's up to the
engineer to figure out how best to use them.  The JSON serialization
components that Android has included seem to violate best practices
here.  (Incidentally, the Android JSON stuff comes from
https://github.com/douglascrockford/JSON-java.  Douglas Crockford is
supposed to be one of those really smart guys that we pay attention
to.  Maybe he should stick to JavaScript?).  The offending code in
JSONObject conveniently checks for null on the key and throws a
checked exception, which is bad.  It would have been better if it just
threw unchecked NPE, or even better, unchecked
IllegalArgumentException, because it's just writing to a map.  But it
was Free Software, so maybe you got what you paid for.  :-(

Sorry you've been troubled by this questionable engineering.  At least
you're free to choose another JSON serialization library.

But I am curious why you're serializing to JSON but not sending or
saving it anywhere, unless I'm misunderstood your previous message?

Doug

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to