java.lang.ThrowableJava
文章发布较早,内容可能过时,阅读注意甄别。
# 定义
public class Throwable implements Serializable {}
1
# 成员变量
- 安全管理类
/* The security manager for the system.
*/
private static volatile SecurityManager security = null;
1
2
3
4
2
3
4
SecurityManager
里有方法
public static void checkPermission(Permission perm)
throws AccessControlException
1
2
3
2
3
checkPermission
方法里面有AccessControlContext stack = getStackAccessControlContext();
getStackAccessControlContext
为原生方法:
/**
* Returns the AccessControl context. i.e., it gets
* the protection domains of all the callers on the stack,
* starting at the first class with a non-null
* ProtectionDomain.
*
* @return the access control context based on the current stack or
* null if there was only privileged system code.
*/
private static native AccessControlContext getStackAccessControlContext();
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 成员函数
- 打印堆栈
/**
* Print our stack trace as an enclosed exception for the specified
* stack trace.
*/
private void printEnclosedStackTrace(PrintStreamOrWriter s,
StackTraceElement[] enclosingTrace,
String caption,
String prefix,
Set<Throwable> dejaVu) {
assert Thread.holdsLock(s.lock());
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
其中Thread.holdsLock(Object obj)为原生方法:
/**
* Returns <tt>true</tt> if and only if the current thread holds the
* monitor lock on the specified object.
*
* <p>This method is designed to allow a program to assert that
* the current thread already holds a specified lock:
* <pre>
* assert Thread.holdsLock(obj);
* </pre>
*
* @param obj the object on which to test lock ownership
* @throws NullPointerException if obj is <tt>null</tt>
* @return <tt>true</tt> if the current thread holds the monitor lock on
* the specified object.
* @since 1.4
*/
public static native boolean holdsLock(Object obj);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 内部类
/**
* Holder class to defer initializing sentinel objects only used
* for serialization.
*/
private static class SentinelHolder {
1
2
3
4
5
2
3
4
5
抽象类:PrintStream
和PrintWriter
的包装类PrintStreamOrWriter
,确保有一个单一printStackTrace
实现
/**
* Wrapper class for PrintStream and PrintWriter to enable a single
* implementation of printStackTrace.
*/
private abstract static class PrintStreamOrWriter {
/** Returns the object to be locked when using this StreamOrWriter */
abstract Object lock();
/** Prints the specified string as a line on this StreamOrWriter */
abstract void println(Object o);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13