On Thu, 21 Oct 2021 18:00:46 GMT, Naoto Sato <na...@openjdk.org> wrote:

>> I'm not reviewer.
>> 
>> I'd like to write down following code without `try-catch`.
>> 
>> var cs = Charset.forName(charsetName, null);
>> if (cs == null) cs = StandardCharsets.UTF_8;
>> 
>> or please find out more easy way.
>
>> I'd like to write down following code without `try-catch`.
> 
> You don't *have to* try-catch those exceptions if you are not interested, as 
> they are subclasses of `RuntimeException`.
> 
>> ```
>> var cs = Charset.forName(charsetName, null);
>> if (cs == null) cs = StandardCharsets.UTF_8;
>> ```
> 
> This could be simplified to
> 
> 
> var cs = Charset.forName(charsetName, StandardCharsets.UTF_8);

@naotoj 
Oh sorry, I'd like to detect fallback charset is used, like: 

var cs = Charset.forName(charsetName, null);
if (cs == null) {
   System.err.println("Used UTF-8 encoding instead of "+charsetName+");
   cs = StandardCharsets.UTF_8;
}

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

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

Reply via email to