Beware of unknown root causes
来源:互联网 发布:大华监控怎么连接网络 编辑:程序博客网 时间:2024/04/29 15:00
http://www.javapractices.com/topic/TopicAction.do?Id=235
All exceptions are based on the Throwable class. By default, all Throwables can have an underlying root cause. The root cause may be set in the Throwable's constructor, or after construction by calling initCause.
Having the root cause is very useful for troubleshooting. However, there is a case in which root causes can cause a problem. When a Throwableis passed over the network, it must first be serialized, and then reconstructed (deserialized) on the other end. If the root cause inside aThrowable object is not known to the receiver on the other end, then what happens? The receiver will throw a NoClassDefFoundError. Of course, this replaces the original exception with something unrelated.
One option is to define a "locked down" exception, which can hold only null as the root cause.
Example
This class is a checked exception which cannot take a root cause.
/** A checked exception that cannot be given a root cause. All calls to {@link #getCause()} will return <tt>null</tt>. This class cannot be subclassed. */public final class LockedDownException extends Exception { /** The sole constructor. No root cause can be passed to this constructor. */ public LockedDownException(String aMessage){ super(aMessage); } /** Always coerces the root cause to <tt>null</tt>. <P>Even though the caller is allowed to call this method, it will never have any effect. The caller is not allowed to set the root cause, neither during construction, nor after construction. */ @Override public synchronized Throwable initCause(Throwable aRootCause) { return super.initCause(null); } /** Simple test harness. */ public static void main(String... aArgs){ LockedDownException ex = new LockedDownException("Hello"); ex.initCause(new IllegalArgumentException("Test")); System.out.println(ex.getCause()); //prints 'null' }}
- Beware of unknown root causes
- Beware of the stopwatch
- Beware of GPU memory bandwidth!!
- 23.1 Causes of exceptions
- 2.3谨慎活跃问题(Beware of Liveness Problems)
- Causes of Oracle Buffer Busy Waits
- Common causes of nans during training
- TKB00064 Running Teamprise as Root User Causes Problems
- Top 10 Causes of Java EE Enterprise Performance Problems
- common causes of the JEE application performance problems
- [论文笔记]Automated Identification of Failure Causes in System Logs
- * TROUBLESHOOTING: Possible Causes of Poor SQL Performance (文档 ID 33089.1)
- Android Out of Memory Error: Causes, Solution and Best practices
- Android Out of Memory Error: Causes, Solution and Best practices
- Android Out of Memory Error Causes, Solution and Best practices
- [转]Beware of Hot Skills Lists: a JonERP.com Disclaimer and Tips List
- Effective Objective-C 2.0: Item 32: Beware of Memory Management with Exception-Safe Code
- read of mingw: unknown error
- AppleScript学习笔记(六)处理程序Handler
- Avoid empty catch blocks
- Be specific in throws clause
- python安装及插件安装
- SICILY 1129. ISBN
- Beware of unknown root causes
- 傀儡进程内存Dump
- linux下fcitx输入法安装
- hdu 3954 Level up 线段树特殊更新节点
- Android binder -- Binder机制编程
- Activity的几种启动方式
- HDU 1969
- XCode5 真机调试及发布应用
- ruby转java 需要重点学习的知识点