@@ -1061,19 +1061,39 @@ public boolean visit(TryStatement node) {
1061
1061
buffer .append ("try " );
1062
1062
node .getBody ().accept (this );
1063
1063
List catchClauses = node .catchClauses ();
1064
- if (catchClauses .size () > 0 ) {
1065
- buffer .append (" catch (e) {\r \n " );
1066
- buffer .append ("if (Clazz.instanceOf (e, " );
1064
+ int size = catchClauses .size ();
1065
+ if (size > 0 ) {
1066
+ String catchEName = "e$$" ;
1067
+ if (size == 1 ) {
1068
+ CatchClause element = (CatchClause ) catchClauses .get (0 );
1069
+ SimpleName exName = element .getException ().getName ();
1070
+ catchEName = exName .getIdentifier ();
1071
+ }
1072
+ buffer .append (" catch (" + catchEName + ") {\r \n " );
1073
+ buffer .append ("if (Clazz.instanceOf (" + catchEName + ", " );
1067
1074
for (Iterator iter = catchClauses .iterator (); iter .hasNext ();) {
1068
1075
CatchClause element = (CatchClause ) iter .next ();
1069
1076
element .getException ().getType ().accept (this );
1070
1077
buffer .append (")) " );
1078
+ SimpleName exName = element .getException ().getName ();
1079
+ String eName = exName .getIdentifier ();
1080
+ boolean notEName = false ;
1081
+ if (!catchEName .equals (eName )) {
1082
+ buffer .append ("{\r \n " );
1083
+ buffer .append ("var " );
1084
+ buffer .append (eName );
1085
+ buffer .append (" = " + catchEName + ";\r \n " );
1086
+ notEName = true ;
1087
+ }
1071
1088
element .getBody ().accept (this );
1089
+ if (notEName ) {
1090
+ buffer .append ("\r \n }" );
1091
+ }
1072
1092
if (iter .hasNext ()) {
1073
- buffer .append (" else if (Clazz.instanceOf (e , " );
1093
+ buffer .append (" else if (Clazz.instanceOf (" + catchEName + " , " );
1074
1094
}
1075
1095
}
1076
- buffer .append (" else {\r \n throw e ;\r \n }\r \n }" );
1096
+ buffer .append (" else {\r \n throw " + catchEName + " ;\r \n }\r \n }" );
1077
1097
}
1078
1098
Block finallys = node .getFinally ();
1079
1099
if (finallys != null ) {
0 commit comments