From 6ea3072f7679fdc8b5c8c62ae22b732307cfcbf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=88=9F?= Date: Thu, 14 May 2020 18:45:12 +0800 Subject: [PATCH] catch exceptions for new --- .../alibaba/testable/generator/StaticNewClassGenerator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/alibaba/testable/generator/StaticNewClassGenerator.java b/src/main/java/com/alibaba/testable/generator/StaticNewClassGenerator.java index c219240..a1e2619 100644 --- a/src/main/java/com/alibaba/testable/generator/StaticNewClassGenerator.java +++ b/src/main/java/com/alibaba/testable/generator/StaticNewClassGenerator.java @@ -42,7 +42,11 @@ public class StaticNewClassGenerator { .beginControlFlow("for (Object o : args)") .addStatement("pts.add(o.getClass())") .endControlFlow() - .addStatement("return type.getConstructor(pts.toArray(new Class[0])).newInstance(args)"); + .beginControlFlow("try") + .addStatement("return type.getConstructor(pts.toArray(new Class[0])).newInstance(args)") + .nextControlFlow("catch (Exception e)") + .addStatement("return null") + .endControlFlow(); } }