I have Oracle’s Java implementation (1.6.0_37) and I’m interested in ClassNotFoundException source code. If you look in it you will see that this class stores it’s own copy of cause:
private Throwable ex;
I just don’t see any point in it – it is totally similar to the field declared in Throwable class.
Could anyone please explain me why does Java class library developers decided to do so?
Probably because nobody thought to remove it.
The
causewas added toThrowablein JDK 1.4; it wasn’t present in 1.3.However, the 1.3 version of
ClassNotFoundExceptiondid have a cause, because this exception can happen when a static initializer fails (actually, due to any loading problem), and debugging without knowing the cause could be extremely frustrating.