Update of /cvsroot/nice/Nice/src/bossa/link
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12009/src/bossa/link
Modified Files:
Compilation.java
Log Message:
Catch exceptions in main, and print the stack trace with the correct
source-level information.
Index: Compilation.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/link/Compilation.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** Compilation.java 28 Aug 2003 15:56:42 -0000 1.12
--- Compilation.java 16 Feb 2004 21:47:12 -0000 1.13
***************
*** 53,56 ****
--- 53,60 ----
(sortedAlternatives.iterator(),
m.javaReturnType(), m.javaReturnType().isVoid(), params);
+
+ if (m.isMain())
+ body = beautifyUncaughtExceptions(body);
+
Gen.setMethodBody(lexp, m.getContract().compile(body));
}
***************
*** 101,104 ****
--- 105,126 ----
}
+ private static Expression beautifyUncaughtExceptions(Expression body)
+ {
+ TryExp res = new TryExp(body, null);
+
+ CatchClause c = new CatchClause("uncaughtException", Type.throwable_type);
+ res.setCatchClauses(c);
+
+ gnu.bytecode.Method print = ClassType.make("nice.lang.dispatch").
+ getDeclaredMethod("printStackTraceWithSourceInfo", 1);
+
+ c.setBody
+ (new ApplyExp
+ (new PrimProcedure(print),
+ new Expression[]{ new ReferenceExp(c.getDeclaration()) }));
+
+ return res;
+ }
+
/****************************************************************
* Java Methods
|