KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > kawa > standard > try_catch


1 package kawa.standard;
2 import kawa.lang.*;
3 import gnu.lists.*;
4 import gnu.expr.*;
5
6 /**
7  * Utility method for try-catch.
8  */

9
10 public class try_catch
11 {
12   public static Expression rewrite (Object JavaDoc try_part, Object JavaDoc clauses)
13   {
14     Translator tr = (Translator) Compilation.getCurrent();
15     Expression try_part_exp = tr.rewrite(try_part);
16     CatchClause prev = null;
17     CatchClause chain = null;
18     FVector vec = (FVector) clauses;
19     int n = vec.size();
20     for (int i = 0; i < n; i++)
21       {
22         Expression cl = Scheme.lambda.rewrite(vec.get(i), tr);
23         if (cl instanceof ErrorExp)
24           return cl;
25         if (! (cl instanceof LambdaExp))
26           return tr.syntaxError("internal error with try-catch");
27         CatchClause ccl = new CatchClause((LambdaExp) cl);
28         if (prev == null)
29           chain = ccl;
30         else
31           prev.setNext(ccl);
32         prev = ccl;
33       }
34     if (try_part_exp instanceof ErrorExp)
35       return try_part_exp;
36     TryExp texp = new TryExp(try_part_exp, null);
37     texp.setCatchClauses(chain);
38     return texp;
39   }
40 }
41
Popular Tags