Skip to content

Instantly share code, notes, and snippets.

@Chouser
Created August 10, 2010 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chouser/517865 to your computer and use it in GitHub Desktop.
Save Chouser/517865 to your computer and use it in GitHub Desktop.
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index f5684f1..130ed5d 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -1719,7 +1719,6 @@ public static class TryExpr implements Expr{
public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
Label startTry = gen.newLabel();
Label endTry = gen.newLabel();
- Label endTryCatch = gen.newLabel();
Label end = gen.newLabel();
Label ret = gen.newLabel();
Label finallyLabel = gen.newLabel();
@@ -1755,7 +1754,6 @@ public static class TryExpr implements Expr{
finallyExpr.emit(C.STATEMENT, objx, gen);
gen.goTo(ret);
}
- gen.mark(endTryCatch);
if(finallyExpr != null)
{
gen.mark(finallyLabel);
@@ -1775,7 +1773,14 @@ public static class TryExpr implements Expr{
gen.visitTryCatchBlock(startTry, endTry, clause.label, clause.c.getName().replace('.', '/'));
}
if(finallyExpr != null)
- gen.visitTryCatchBlock(startTry, endTryCatch, finallyLabel, null);
+ {
+ gen.visitTryCatchBlock(startTry, endTry, finallyLabel, null);
+ for(int i = 0; i < catchExprs.count(); i++)
+ {
+ CatchClause clause = (CatchClause) catchExprs.nth(i);
+ gen.visitTryCatchBlock(clause.label, clause.endLabel, finallyLabel, null);
+ }
+ }
for(int i = 0; i < catchExprs.count(); i++)
{
CatchClause clause = (CatchClause) catchExprs.nth(i);
class Foo {
public static void main(String[] args) throws Exception{
try {
System.out.println("try");
}
catch(Exception e) {
System.out.println("catch");
}
finally {
System.out.println("finally");
throw new Exception("from finally");
}
}
}
$ javap -c Foo
Compiled from "foo.java"
class Foo extends java.lang.Object{
Foo();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]) throws java.lang.Exception;
Code:
0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #3; //String try
5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
11: ldc #5; //String finally
13: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
16: new #6; //class java/lang/Exception
19: dup
20: ldc #7; //String from finally
22: invokespecial #8; //Method java/lang/Exception."<init>":(Ljava/lang/String;)V
25: athrow
26: astore_1
27: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
30: ldc #9; //String catch
32: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
35: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
38: ldc #5; //String finally
40: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
43: new #6; //class java/lang/Exception
46: dup
47: ldc #7; //String from finally
49: invokespecial #8; //Method java/lang/Exception."<init>":(Ljava/lang/String;)V
52: athrow
53: astore_2
54: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
57: ldc #5; //String finally
59: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
62: new #6; //class java/lang/Exception
65: dup
66: ldc #7; //String from finally
68: invokespecial #8; //Method java/lang/Exception."<init>":(Ljava/lang/String;)V
71: athrow
Exception table:
from to target type
0 8 26 Class java/lang/Exception
0 8 53 any
26 35 53 any
53 54 53 any
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment