On Thu, 21 Oct 2021 09:33:30 GMT, Daniel Fuchs <dfu...@openjdk.org> wrote:

>> Right, I think both try-catch usages will be removed.
>
> Apparently `IllegalCharsetNameException` or `IllegalArgumentException` could 
> still be thrown - so removing the `try-catch` would be a change of behaviour 
> in those cases. It all depends on whether there is a chance that these 
> exceptions could be thrown in this particular context (with these particular 
> input parameters) - which I am not able to tell - but maybe someone more 
> familiar with this code could...

I first thought of swallowing all exceptions in 2-arg forName(), but decided 
not to do that. Because `IllegalArgumentException` and 
`IllegalCharsetNameException` are for the validity of the passed `charsetName`, 
like detecting `null` or invalid chars like "😱". On the other hand, 
`UnsupportedCharsetException` is for the availability which varies depending on 
the user's settings and or platform, which can be safely replaced with 
`fallback` charset. So yes, it is not totally getting rid of `try-catch` but it 
avoids `UnsupportedCharsetException` which is only detectable at runtime.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6045

Reply via email to