ABSTRACT

If a ThreadDeath error is not re-thrown, the thread in question might not actually die.

EXPLANATION

ThreadDeath errors should only be caught if an applications needs to clean up after being terminated asynchronously. If a ThreadDeath error is caught, it is important that it be re-thrown so that the thread actually dies. The purpose of throwing ThreadDeath is to stop a thread. If ThreadDeath is swallowed, it can prevent a thread from stopping and result in unexpected behavior since whoever originally threw ThreadDeath expects the thread to stop.

Example 1: The following code catches ThreadDeath but does not re-throw it.


try
{
//some code
}
catch(ThreadDeath td)
{
//clean up code
}

REFERENCES

[1] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 691

[2] Sun Microsystems, Inc. Java Sun Tutorial

[3] Scott Oaks, Henry Wong Java Threads O'Reilly