Common place to turn checked exceptions into unchecked exceptions
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java b/jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java
index a25fe6b..ed78dbb 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java
@@ -39,11 +39,11 @@
void actionEx(X arg) throws IOException;
}
+ // Maybe change to java.io.UncheckedIOException
/**
* Convert an {@link IOException} into a {@link RuntimeIOException}.
* <p>
* Idiom:
- *
* <pre>
* catch(IOException ex) { throw new exception(ex); }
* </pre>
@@ -59,7 +59,6 @@
* Convert an {@link IOException} into a {@link RuntimeIOException}.
* <p>
* Idiom:
- *
* <pre>
* catch(IOException ex) { throw new exception("Oh dear", ex); }
* </pre>
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/lib/Lib.java b/jena-base/src/main/java/org/apache/jena/atlas/lib/Lib.java
index e77ab46..bbc2b43 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/lib/Lib.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/Lib.java
@@ -110,6 +110,18 @@
return new UnsupportedOperationException(Lib.className(object) + "." + method);
}
+ /**
+ * Return a {@linkplain RuntimeException}. If the argument is already
+ * {@code RuntimeException}, return the argument. Otherwise, wrap in
+ * {@code RuntimeException}, with the same message, and return the
+ * {@code RuntimeException}
+ */
+ public static RuntimeException runtimeException(Exception ex) {
+ if ( ex instanceof RuntimeException ex2)
+ throw ex2;
+ return new RuntimeException(ex.getMessage(), ex);
+ }
+
/** Do two lists have the same elements without considering the order of the lists nor duplicates? */
public static <T> boolean equalsListAsSet(List<T> list1, List<T> list2) {
if ( list1 == null && list2 == null )