Skip to content

Commit f6bcd6c

Browse files
author
Troy Melhase
committed
Adds support for empty 'catch' statements.
1 parent f4725cc commit f6bcd6c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

java2python/compiler/visitor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ def acceptCatch(self, node, memo):
364364
cname = '.'.join(n.text for n in tnames)
365365
cvar = decl.firstChildOfType(tokens.IDENT)
366366
block = node.firstChildOfType(tokens.BLOCK_SCOPE)
367+
if not block.children:
368+
self.factory.expr(left='pass', parent=self)
367369
self.expr.fs = FS.lsrc
368370
self.expr.right = self.factory.expr(fs=FS.l+' as '+FS.r, left=cname, right=cvar)
369371
self.walk(block, memo)

test/Try1.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Try1 {
2+
3+
public static void main(String[] args) {
4+
try {
5+
System.out.println(0);
6+
} catch (Exception e) {
7+
}
8+
9+
10+
try {
11+
System.out.println(1);
12+
} catch (Exception e) {
13+
System.out.println(2);
14+
}
15+
16+
}
17+
}

0 commit comments

Comments
 (0)