Repository navigation
Expand file tree
/
Copy pathActError.java
More file actions
53 lines (48 loc) · 1.67 KB
/
Copy pathActError.java
File metadata and controls
53 lines (48 loc) · 1.67 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
package act.util;
import act.app.*;
import org.osgl.util.C;
import org.osgl.util.S;
import java.util.List;
public interface ActError {
Throwable getCauseOrThis();
SourceInfo sourceInfo();
List<String> stackTrace();
public static class Util {
public static List<String> stackTraceOf(Throwable t, ActError root) {
List<String> l = C.newList();
while (null != t) {
StackTraceElement[] a = t.getStackTrace();
for (StackTraceElement e : a) {
l.add("at " + e.toString());
}
t = t.getCause();
if (t == root) {
break;
}
if (null != t) {
l.add("Caused by " + t.toString());
}
}
return l;
}
public static SourceInfo loadSourceInfo(StackTraceElement[] stackTraceElements, Class<? extends ActError> errClz) {
DevModeClassLoader cl = (DevModeClassLoader) App.instance().classLoader();
for (StackTraceElement stackTraceElement : stackTraceElements) {
int line = stackTraceElement.getLineNumber();
if (line <= 0) {
continue;
}
String className = stackTraceElement.getClassName();
if (S.eq(errClz.getName(), className)) {
continue;
}
Source source = cl.source(className);
if (null == source) {
continue;
}
return new SourceInfoImpl(source, line);
}
return null;
}
}
}