view src/luan/interp/TryStmt.java @ 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
children
line wrap: on
line source

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);
			}
		}
	}
}