Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef9bc32

Browse files
author
zhourenjian
committed
Fixed bug [ 1690362 ] Invalid name of exception object inside catch block
Now Generating JavaScript for try/catch block will assign default exception variable "e" to a new exception variable, if needed.
1 parent 4278beb commit ef9bc32

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTKeywordVisitor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,20 @@ public boolean visit(TryStatement node) {
10621062
CatchClause element = (CatchClause) iter.next();
10631063
element.getException().getType().accept(this);
10641064
buffer.append(")) ");
1065+
SimpleName exName = element.getException().getName();
1066+
String eName = exName.getIdentifier();
1067+
boolean notEName = false;
1068+
if (!"e".equals(eName)) {
1069+
buffer.append("{\r\n");
1070+
buffer.append("var ");
1071+
buffer.append(eName);
1072+
buffer.append(" = e;\r\n");
1073+
notEName = true;
1074+
}
10651075
element.getBody().accept(this);
1076+
if (notEName) {
1077+
buffer.append("\r\n}");
1078+
}
10661079
if (iter.hasNext()) {
10671080
buffer.append(" else if (Clazz.instanceOf (e, ");
10681081
}

0 commit comments

Comments
 (0)