view core/src/luan/impl/TryStmt.java @ 171:3dcb0f9bee82

add core component git-svn-id: https://luan-java.googlecode.com/svn/trunk@172 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 22 Jun 2014 05:41:22 +0000
parents src/luan/impl/TryStmt.java@4eaee12f6c65
children
line wrap: on
line source

package luan.impl;

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