@@ -412,10 +412,8 @@ Object encode(Object str, @SuppressWarnings("unused") Object encoding, @Suppress
412
412
@ TruffleBoundary
413
413
private PBytes encodeString (String self , String encoding , String errors ) {
414
414
CodingErrorAction errorAction = convertCodingErrorAction (errors );
415
- Charset charset ;
416
- try {
417
- charset = getCharset (encoding );
418
- } catch (UnsupportedCharsetException | IllegalCharsetNameException e ) {
415
+ Charset charset = getCharset (encoding );
416
+ if (charset == null ) {
419
417
throw raise (LookupError , "unknown encoding: %s" , encoding );
420
418
}
421
419
try {
@@ -545,10 +543,8 @@ private ByteBuffer getBytesBuffer(PIBytesLike bytesLike) {
545
543
@ TruffleBoundary
546
544
String decodeBytes (ByteBuffer bytes , String encoding , String errors ) {
547
545
CodingErrorAction errorAction = convertCodingErrorAction (errors );
548
- Charset charset ;
549
- try {
550
- charset = getCharset (encoding );
551
- } catch (UnsupportedCharsetException | IllegalCharsetNameException e ) {
546
+ Charset charset = getCharset (encoding );
547
+ if (charset == null ) {
552
548
throw raise (LookupError , "unknown encoding: %s" , encoding );
553
549
}
554
550
try {
@@ -627,10 +623,9 @@ abstract static class CodecsLookupNode extends PythonBuiltinNode {
627
623
// This is replaced in the core _codecs.py with the full functionality
628
624
@ Specialization
629
625
Object lookup (String encoding ) {
630
- try {
631
- getCharset (encoding );
626
+ if (getCharset (encoding ) != null ) {
632
627
return true ;
633
- } catch ( UnsupportedCharsetException | IllegalCharsetNameException e ) {
628
+ } else {
634
629
return PNone .NONE ;
635
630
}
636
631
}
0 commit comments