aherbert commented on a change in pull request #729:
URL: https://github.com/apache/commons-lang/pull/729#discussion_r588445520



##########
File path: src/changes/changes.xml
##########
@@ -100,6 +100,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="jochen">Introduce the use of 
@Nonnull, and @Nullable, and the Objects class as a helper tool.</action>
     <action                   type="add" dev="ggregory" due-to="Arturo Bernal, 
Gary Gregory">Add and use true and false String constants #714.</action>
     <action                   type="add" dev="ggregory" due-to="Arturo Bernal, 
Gary Gregory">Add and use ObjectUtils.requireNonEmpty() #716.</action>
+    <action issue="LANG-1647" type="add" dev="abernal"  due-to="">Check if an 
throwable is a checked exception.</action>

Review comment:
       This is in the wrong place

##########
File path: src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
##########
@@ -586,6 +586,30 @@ public static int indexOfType(final Throwable throwable, 
final Class<? extends T
         return indexOf(throwable, type, fromIndex, true);
     }
 
+    /**
+     * Return whether the given throwable is a checked exception:
+     * that is, neither a RuntimeException nor an Error.
+     *
+     * <pre>
+     * ExceptionUtils.isCheckedException(new Exception())                    = 
true
+     * ExceptionUtils.isCheckedException(new SQLException())                 = 
true
+     * ExceptionUtils.isCheckedException(new RuntimeException())             = 
false
+     * ExceptionUtils.isCheckedException(new IllegalArgumentException(""))   = 
false
+     * ExceptionUtils.isCheckedException(new Throwable())                    = 
true
+     * ExceptionUtils.isCheckedException(null)                               = 
false
+     * </pre>
+     *
+     * @param throwable the throwable to check
+     * @return whether the throwable is a checked exception
+     * @see java.lang.Exception
+     * @see java.lang.RuntimeException
+     * @see java.lang.Error
+     * @since 3.12.1
+     */
+    public static boolean isCheckedException(final Throwable throwable) {
+        return throwable != null && !(throwable instanceof RuntimeException || 
throwable instanceof Error);

Review comment:
       `instanceof` handles null. Does this work if you remove the `throwable 
!= null &&`?
   
   I would expect in the majority of cases this would be called with a non-null 
object so this simplifies the code.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to