< prev index next >

src/java.base/share/classes/java/time/format/DateTimePrintContext.java

Print this page

        

@@ -300,17 +300,14 @@
      * @param field  the field to find, not null
      * @return the value, null if not found and optional is true
      * @throws DateTimeException if the field is not available and the section is not optional
      */
     Long getValue(TemporalField field) {
-        try {
+        if (optional == 0) {
             return temporal.getLong(field);
-        } catch (DateTimeException ex) {
-            if (optional > 0) {
-                return null;
-            }
-            throw ex;
+        } else {
+            return temporal.isSupported(field) ? temporal.getLong(field) : null;
         }
     }
 
     //-----------------------------------------------------------------------
     /**
< prev index next >