
org.snapscript.platform.standard.DelegateConstructorInvocation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.platform.standard;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.snapscript.core.InternalStateException;
import org.snapscript.core.function.Invocation;
import org.snapscript.core.scope.Scope;
public class DelegateConstructorInvocation implements Invocation {
private final Constructor constructor;
public DelegateConstructorInvocation(Constructor constructor) {
this.constructor = constructor;
}
@Override
public Object invoke(Scope scope, Object value, Object... arguments) throws Exception {
try {
return constructor.newInstance(arguments);
}catch(InvocationTargetException cause) {
Throwable target = cause.getTargetException();
if(target != null) {
throw new InternalStateException("Error occured invoking " + constructor, target);
}
throw cause;
}catch(InternalError cause) {
Throwable target = cause.getCause();
if(target != null) {
throw new InternalStateException("Error occured invoking " + constructor, target);
}
throw cause;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy