I want to assign an error code to each error, so I think I have to find all sub classes of java.lang.Throwable
in the JVM. The classes may or may not have been already loaded in the JVM. Or is there another solution?
I have read the similar question How do you find all subclasses of a given class in Java? , and tried the ClassGraph and org.reflections:reflections:0.10.2 , but they can not find the Classes in jdk
like the java.lang.NullPointerException
in java.lang
.
The code using ClassGraph:
ClassGraph classGraph = new ClassGraph() ;
ScanResult result = classGraph.enableAllInfo().whitelistPackages( "java.lang" ).scan() ;
result.getAllClasses().forEach( c -> System.out.println(c) ) ;