Package com.cloudbees.groovy.cps.impl

Source Code of com.cloudbees.groovy.cps.impl.ThrowBlock

package com.cloudbees.groovy.cps.impl;

import com.cloudbees.groovy.cps.Block;
import com.cloudbees.groovy.cps.Continuation;
import com.cloudbees.groovy.cps.Env;
import com.cloudbees.groovy.cps.Next;

/**
* @author Kohsuke Kawaguchi
*/
public class ThrowBlock implements Block {
    private final Block exp;

    public ThrowBlock(Block exp) {
        this.exp = exp;
    }

    public Next eval(final Env e, Continuation _) {
        return new Next(exp,e,new Continuation() {
            public Next receive(Object t) {
                if (t==null) {
                    t = new NullPointerException();
                }
                if (!(t instanceof Throwable)) {
                    t = new ClassCastException(t.getClass()+" cannot be cast to Throwable");
                }
                // TODO: fake the stack trace information

                Continuation v = e.getExceptionHandler(Throwable.class.cast(t).getClass());
                return v.receive(t);
            }
        });
    }

    private static final long serialVersionUID = 1L;
}
TOP

Related Classes of com.cloudbees.groovy.cps.impl.ThrowBlock

TOP
Copyright © 2015 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.