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

TAKETODAY / today-infrastructure / 8308118446

16 Mar 2024 01:26PM UTC coverage: 78.393% (+0.02%) from 78.374%
8308118446

push

github

TAKETODAY
:white_check_mark:

63592 of 86119 branches covered (73.84%)

Branch coverage included in aggregate %.

157000 of 195273 relevant lines covered (80.4%)

3.41 hits per line

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

78.57
today-context/src/main/java/cn/taketoday/scheduling/support/DelegatingErrorHandlingRunnable.java
1
/*
2
 * Copyright 2017 - 2024 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package cn.taketoday.scheduling.support;
19

20
import java.lang.reflect.UndeclaredThrowableException;
21

22
import cn.taketoday.lang.Assert;
23
import cn.taketoday.util.ErrorHandler;
24

25
/**
26
 * Runnable wrapper that catches any exception or error thrown from its
27
 * delegate Runnable and allows an {@link ErrorHandler} to handle it.
28
 *
29
 * @author Juergen Hoeller
30
 * @author Mark Fisher
31
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
32
 * @since 4.0
33
 */
34
public class DelegatingErrorHandlingRunnable implements Runnable {
35

36
  private final Runnable delegate;
37

38
  private final ErrorHandler errorHandler;
39

40
  /**
41
   * Create a new DelegatingErrorHandlingRunnable.
42
   *
43
   * @param delegate the Runnable implementation to delegate to
44
   * @param errorHandler the ErrorHandler for handling any exceptions
45
   */
46
  public DelegatingErrorHandlingRunnable(Runnable delegate, ErrorHandler errorHandler) {
2✔
47
    Assert.notNull(delegate, "Delegate is required");
3✔
48
    Assert.notNull(errorHandler, "ErrorHandler is required");
3✔
49
    this.delegate = delegate;
3✔
50
    this.errorHandler = errorHandler;
3✔
51
  }
1✔
52

53
  @Override
54
  public void run() {
55
    try {
56
      this.delegate.run();
3✔
57
    }
58
    catch (UndeclaredThrowableException ex) {
×
59
      this.errorHandler.handleError(ex.getUndeclaredThrowable());
×
60
    }
61
    catch (Throwable ex) {
1✔
62
      this.errorHandler.handleError(ex);
4✔
63
    }
1✔
64
  }
1✔
65

66
  @Override
67
  public String toString() {
68
    return "DelegatingErrorHandlingRunnable for " + this.delegate;
×
69
  }
70

71
}
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

© 2025 Coveralls, Inc