I have a java file and I want to get the exception message for the exception type after the throw keyword
// this is the code of D:\\ProjectFile\\AST\\Test\\000001\\test.java
if (len < 0 || offset < 0 || len + offset > b.length) {
String str = "index out of bounds";
throw new IndexOutOfBoundsException(s);
}
For example, I want to get the string, "index out of bounds" inthe "D:\ProjectFile\AST\Test\000001\test.java", because he is a property of IndexOutOfBoundsException
So, When I use spoon, I don't find enough examples to teach me
public static void main(String[] args) {
Launcher launcher = new Launcher();
launcher.addInputResource("D:\\ProjectFile\\AST\\Test\\000001\\test.java");
launcher.buildModel();
CtModel model = launcher.getModel();
List<CtThrow> throwList = model.getElements(new TypeFilter<>(CtThrow.class));
for (int i = 0; i < throwList.size();i++) {
System.out.println(throwList.get(i).getThrownExpression());
}
}
Using the code above, I can only get the following:
new java.lang.IndexOutOfBoundsException(s)
I can not get the value of s
.
I want to be able to check the constructor of this exception type and get its property value, how should I do this?
try it :