• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yuu-nkjm / sorm4j / #518

13 Mar 2025 07:20AM UTC coverage: 93.617% (-0.03%) from 93.65%
#518

push

Yuu NAKAJIMA
RefactoringTry

813 of 931 branches covered (87.33%)

Branch coverage included in aggregate %.

56 of 63 new or added lines in 10 files covered. (88.89%)

21 existing lines in 3 files now uncovered.

4188 of 4411 relevant lines covered (94.94%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/sorm4j/src/main/java/org/nkjmlab/sorm4j/internal/util/function/ThrowableRunnable.java
1
package org.nkjmlab.sorm4j.internal.util.function;
2

3
import java.util.function.Consumer;
4

5
/**
6
 * A functional interface similar to {@link Runnable}, but allows throwing checked exceptions. This
7
 * interface enables lambda expressions and method references to handle exceptions explicitly within
8
 * the execution logic.
9
 *
10
 * <p>Use {@link #toRunnable(ThrowableRunnable, Consumer)} to convert it into a standard {@link
11
 * Runnable} while handling exceptions gracefully.
12
 *
13
 * @author yuu_nkjm
14
 */
15
@FunctionalInterface
16
public interface ThrowableRunnable {
17

18
  /**
19
   * Executes the operation, allowing checked exceptions to be thrown.
20
   *
21
   * @throws Exception if an error occurs during execution
22
   */
23
  void run() throws Exception;
24

25
  /**
26
   * Converts a {@code ThrowableRunnable} into a {@link Runnable} by wrapping the execution inside a
27
   * try-catch block. If an exception occurs, it is passed to the given exception handler.
28
   *
29
   * <p>This method allows integrating exception-throwing runnables into standard Java functional
30
   * interfaces while handling errors in a controlled manner.
31
   *
32
   * @param onTry the {@code ThrowableRunnable} to be executed
33
   * @param exceptionHandler a {@code Consumer} to handle any thrown exceptions
34
   * @return a {@code Runnable} that wraps the given {@code ThrowableRunnable} with exception
35
   *     handling
36
   */
37
  public static Runnable toRunnable(ThrowableRunnable onTry, Consumer<Exception> exceptionHandler) {
38
    return () -> {
1✔
39
      try {
40
        onTry.run();
1✔
41
      } catch (Exception e) {
1✔
NEW
42
        exceptionHandler.accept(e);
×
43
      }
1✔
44
    };
1✔
45
  }
46
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc