Skip to content

Commit 6e45deb

Browse files
authored
Merge pull request #1000: [core] add ExceptionUtils.ignoring
2 parents a50f52b + 016d508 commit 6e45deb

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

core/src/main/java/cz/o2/proxima/core/util/ExceptionUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import cz.o2.proxima.core.functional.Consumer;
2020
import cz.o2.proxima.core.functional.UnaryFunction;
2121
import java.io.Serializable;
22+
import lombok.extern.slf4j.Slf4j;
2223

2324
/** Utilities related to exception throwing and handling. */
25+
@Slf4j
2426
public class ExceptionUtils {
2527

2628
/**
@@ -184,5 +186,14 @@ public static void rethrowAsIllegalStateException(Throwable cause) {
184186
throw new IllegalStateException(cause);
185187
}
186188

189+
/** Swallow any Exception. */
190+
public static void ignoring(ThrowingRunnable runnable) {
191+
try {
192+
runnable.run();
193+
} catch (Exception ex) {
194+
log.warn("Caught error, ignoring as instructed.", ex);
195+
}
196+
}
197+
187198
private ExceptionUtils() {}
188199
}

core/src/test/java/cz/o2/proxima/core/util/ExceptionUtilsTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,13 @@ public void testRethrowIllegalStateException() {
6969
assertEquals("ex", ex.getCause().getMessage());
7070
}
7171
}
72+
73+
@Test
74+
public void testIgnoring() {
75+
ExceptionUtils.ignoring(
76+
() -> {
77+
throw new IllegalStateException("ex");
78+
});
79+
assertTrue(true);
80+
}
7281
}

0 commit comments

Comments
 (0)