It would be simple if the language designers focused on usability vs pristine accuracy. Java, obviously went for the latter.
Thus if you were to ask whether an illegal charset is supported, it won't return false, it will decide to throw the
IllegalCharsetNameException exception. How precise.
How annoying. Now when all you wanted was to check for the availability of a charset, suddenly you end up checking for exceptions as well as the return value from Charset.isSupported.
Such is the art of programming in Java.
1 comment:
After recovering from my facepalm, I decided to use Charset.availableCharsets().containsKey(...) instead of messing with try-catch blocks.
Post a Comment