blob: 072e1a1031fe8ece118a0a632b98f2248e5690dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package org.checkerframework.javacutil;
/**
* Handle errors detected in utility classes. By default, the error reporter
* throws a RuntimeException, but clients of the utility library may register
* a handler to change the behavior. For example, type checkers can direct
* errors to the org.checkerframework.framework.source.SourceChecker class.
*/
public class ErrorReporter {
protected static ErrorHandler handler = null;
/**
* Register a handler to customize error reporting.
*/
public static void setHandler(ErrorHandler h) {
handler = h;
}
/**
* Log an error message and abort processing.
* Call this method instead of raising an exception.
*
* @param msg The error message to log.
*/
public static void errorAbort(String msg) {
if (handler != null) {
handler.errorAbort(msg);
} else {
throw new RuntimeException(msg, new Throwable());
}
}
public static void errorAbort(String msg, Throwable cause) {
if (handler != null) {
handler.errorAbort(msg, cause);
} else {
throw new RuntimeException(msg, cause);
}
}
}
|