Name: akC45999 Date: 03/12/98
The description of java.lang.Class.forName() reads:
Given the fully-qualified name for a class or interface, this method attempts
to locate, load and link the class. If it succeeds, returns the Class object
representing the class. If it fails, the method throws a ClassNotFoundException.
Loading and linking may fail due to a number of reasons.
Each such reason has corresponding exception (usually sublclass of LinkageError).
But if Class.forName() throws ClassNotFoundException, the reason remains unknown
to the calling program. This make debugging much harder.
Proposed API change:
Add a method getLoadingException() to the class ClassNotFoundException
to return the actual exception thrown during loading and linking.
This is similiar to
used in java.lang reflect package to solve similiar problem:
provide the exception thrown during method invocation made by means
of reflection mechanism.
Another possible solution is to allow loading exceptions to pass through
the invocation of Class.forName(). This is less preferable for following reasons:
1. such specification change is not backward-compatible
2. the Class.forName() become less convenient to use as it must be surrounded
with more catch clauses
3. if the set of loading and linking exceptions will ever change, this will cause
the change of the Class.forName() specification