changeset 101:8ebcccca13ab

add missing TryStmt git-svn-id: https://luan-java.googlecode.com/svn/trunk@102 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 10 Jun 2013 23:07:25 +0000
parents 6c827f7275df
children 90b918cbf888
files src/luan/interp/TryStmt.java
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
diff -r 6c827f7275df -r 8ebcccca13ab src/luan/interp/TryStmt.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/interp/TryStmt.java	Mon Jun 10 23:07:25 2013 +0000
@@ -0,0 +1,30 @@
+package luan.interp;
+
+import luan.Luan;
+import luan.LuanException;
+
+
+final class TryStmt implements Stmt {
+	private final Stmt tryBlock;
+	private final int iExceptionVar;
+	private final Stmt catchBlock;
+
+	TryStmt(Stmt tryBlock,int iExceptionVar,Stmt catchBlock) {
+		this.tryBlock = tryBlock;
+		this.iExceptionVar = iExceptionVar;
+		this.catchBlock = catchBlock;
+	}
+
+	@Override public void eval(LuanStateImpl luan) throws LuanException {
+		try {
+			tryBlock.eval(luan);
+		} catch(LuanException e) {
+			try {
+				luan.stackSet( iExceptionVar, e );
+				catchBlock.eval(luan);
+			} finally {
+				luan.stackClear(iExceptionVar,iExceptionVar+1);
+			}
+		}
+	}
+}