org.mozilla.javascript.Context.throwAsScriptRuntimeEx()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 JavaScript  
字(8.3k)|赞(0)|评价(0)|浏览(180)

本文整理了Java中org.mozilla.javascript.Context.throwAsScriptRuntimeEx()方法的一些代码示例,展示了Context.throwAsScriptRuntimeEx()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.throwAsScriptRuntimeEx()方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:throwAsScriptRuntimeEx

Context.throwAsScriptRuntimeEx介绍

[英]Rethrow the exception wrapping it as the script runtime exception. Unless the exception is instance of EcmaError or EvaluatorException it will be wrapped as WrappedException, a subclass of EvaluatorException. The resulting exception object always contains source name and line number of script that triggered exception.

This method always throws an exception, its return value is provided only for convenience to allow a usage like:

throw Context.throwAsScriptRuntimeEx(ex);

to indicate that code after the method is unreachable.
[中]重新显示异常,将其包装为脚本运行时异常。除非异常是EcmaError或EvaluatorException的实例,否则它将被包装为WrappedException,它是EvaluatorException的子类。生成的异常对象始终包含触发异常的脚本的源名称和行号。
此方法始终引发异常,其返回值仅为方便使用而提供,例如:

throw Context.throwAsScriptRuntimeEx(ex);

以指示无法访问该方法后的代码。

代码示例

代码示例来源:origin: ro.isdc.wro4j/rhino

/**
 * Crete new Delegator instance.
 * The default implementation calls this.getClass().newInstance().
 *
 * @see #construct(Context cx, Scriptable scope, Object[] args)
 */
protected Delegator newInstance()
{
  try {
    return this.getClass().newInstance();
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: rhino/js

/**
 * Crete new Delegator instance.
 * The default implementation calls this.getClass().newInstance().
 *
 * @see #construct(Context cx, Scriptable scope, Object[] args)
 */
protected Delegator newInstance()
{
  try {
    return this.getClass().newInstance();
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

/**
 * Crete new Delegator instance.
 * The default implementation calls this.getClass().newInstance().
 *
 * @see #construct(Context cx, Scriptable scope, Object[] args)
 */
protected Delegator newInstance()
{
  try {
    return (Delegator)this.getClass().newInstance();
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: geogebra/geogebra

/**
 * Crete new Delegator instance.
 * The default implementation calls this.getClass().newInstance().
 *
 * @see #construct(Context cx, Scriptable scope, Object[] args)
 */
protected Delegator newInstance()
{
  try {
    return this.getClass().newInstance();
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: com.github.tntim96/rhino

/**
 * Crete new Delegator instance.
 * The default implementation calls this.getClass().newInstance().
 *
 * @see #construct(Context cx, Scriptable scope, Object[] args)
 */
protected Delegator newInstance()
{
  try {
    return this.getClass().newInstance();
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: io.apigee/rhino

/**
 * Crete new Delegator instance.
 * The default implementation calls this.getClass().newInstance().
 *
 * @see #construct(Context cx, Scriptable scope, Object[] args)
 */
protected Delegator newInstance()
{
  try {
    return this.getClass().newInstance();
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: com.github.tntim96/rhino

@Override
public void run() {
  try {
    Global.pipe(fromProcess, from, to);
  } catch (IOException ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: ro.isdc.wro4j/rhino

@Override
public void run() {
  try {
    Global.pipe(fromProcess, from, to);
  } catch (IOException ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: rhino/js

Object newInstance(Object[] args)
{
  Constructor<?> ctor = ctor();
  try {
    try {
      return ctor.newInstance(args);
    } catch (IllegalAccessException ex) {
      if (!VMBridge.instance.tryToMakeAccessible(ctor)) {
        throw Context.throwAsScriptRuntimeEx(ex);
      }
    }
    return ctor.newInstance(args);
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: geogebra/geogebra

Object newInstance(Object[] args)
{
  Constructor<?> ctor = ctor();
  try {
    try {
      return ctor.newInstance(args);
    } catch (IllegalAccessException ex) {
      if (!VMBridge.instance.tryToMakeAccessible(ctor)) {
        throw Context.throwAsScriptRuntimeEx(ex);
      }
    }
    return ctor.newInstance(args);
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

Object newInstance(Object[] args)
{
  Constructor ctor = ctor();
  try {
    try {
      return ctor.newInstance(args);
    } catch (IllegalAccessException ex) {
      if (!VMBridge.instance.tryToMakeAccessible(ctor)) {
        throw Context.throwAsScriptRuntimeEx(ex);
      }
    }
    return ctor.newInstance(args);
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: io.apigee/rhino

Object newInstance(Object[] args)
{
  Constructor<?> ctor = ctor();
  try {
    try {
      return ctor.newInstance(args);
    } catch (IllegalAccessException ex) {
      if (!VMBridge.instance.tryToMakeAccessible(ctor)) {
        throw Context.throwAsScriptRuntimeEx(ex);
      }
    }
    return ctor.newInstance(args);
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: ro.isdc.wro4j/rhino

Object newInstance(Object[] args)
{
  Constructor<?> ctor = ctor();
  try {
    try {
      return ctor.newInstance(args);
    } catch (IllegalAccessException ex) {
      if (!VMBridge.instance.tryToMakeAccessible(ctor)) {
        throw Context.throwAsScriptRuntimeEx(ex);
      }
    }
    return ctor.newInstance(args);
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: com.github.tntim96/rhino

Object newInstance(Object[] args)
{
  Constructor<?> ctor = ctor();
  try {
    try {
      return ctor.newInstance(args);
    } catch (IllegalAccessException ex) {
      if (!VMBridge.instance.tryToMakeAccessible(ctor)) {
        throw Context.throwAsScriptRuntimeEx(ex);
      }
    }
    return ctor.newInstance(args);
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
}

代码示例来源:origin: org.wso2.bpel.extensions/ode-bpel-extensions-e4x

/**
 * This methods is exposed to the JS environment and supports loading
 * JavaScript libraries from the deployment unit directory. 
 */
public static void load(Context cx, Scriptable thisObj, Object[] args,
    Function funObj) {
  TopLevelFunctions thiz = (TopLevelFunctions) getTopLevelScope(thisObj);
  for (int i = 0; i < args.length; i++) {
    // Assumes resource's path is given relative to the service archive
    URI uri = thiz._duDir.resolve(Context.toString(args[i]));
    try {
      InputStream is = uri.toURL().openStream();
      cx.evaluateReader(thiz, new InputStreamReader(is), "<importJS>", 1, null);
    } catch (MalformedURLException e) {
      throw Context.throwAsScriptRuntimeEx(e);
    } catch (IOException e) {
      throw Context.throwAsScriptRuntimeEx(e);
    }
  }
}

代码示例来源:origin: geogebra/geogebra

private ModuleScript getModule(Context cx, String id, URI uri, URI base) {
  try {
    final ModuleScript moduleScript =
        moduleScriptProvider.getModuleScript(cx, id, uri, base, paths);
    if (moduleScript == null) {
      throw ScriptRuntime.throwError(cx, nativeScope, "Module \""
          + id + "\" not found.");
    }
    return moduleScript;
  }
  catch(RuntimeException e) {
    throw e;
  }
  catch(Exception e) {
    throw Context.throwAsScriptRuntimeEx(e);
  }
}

代码示例来源:origin: io.apigee/rhino

private ModuleScript getModule(Context cx, String id, URI uri, URI base) {
  try {
    final ModuleScript moduleScript =
        moduleScriptProvider.getModuleScript(cx, id, uri, base, paths);
    if (moduleScript == null) {
      throw ScriptRuntime.throwError(cx, nativeScope, "Module \""
          + id + "\" not found.");
    }
    return moduleScript;
  }
  catch(RuntimeException e) {
    throw e;
  }
  catch(Exception e) {
    throw Context.throwAsScriptRuntimeEx(e);
  }
}

代码示例来源:origin: com.github.tntim96/rhino

private ModuleScript getModule(Context cx, String id, URI uri, URI base) {
  try {
    final ModuleScript moduleScript =
        moduleScriptProvider.getModuleScript(cx, id, uri, base, paths);
    if (moduleScript == null) {
      throw ScriptRuntime.throwError(cx, nativeScope, "Module \""
          + id + "\" not found.");
    }
    return moduleScript;
  }
  catch(RuntimeException e) {
    throw e;
  }
  catch(Exception e) {
    throw Context.throwAsScriptRuntimeEx(e);
  }
}

代码示例来源:origin: ro.isdc.wro4j/rhino

private ModuleScript getModule(Context cx, String id, URI uri, URI base) {
  try {
    final ModuleScript moduleScript =
        moduleScriptProvider.getModuleScript(cx, id, uri, base, paths);
    if (moduleScript == null) {
      throw ScriptRuntime.throwError(cx, nativeScope, "Module \""
          + id + "\" not found.");
    }
    return moduleScript;
  }
  catch(RuntimeException e) {
    throw e;
  }
  catch(Exception e) {
    throw Context.throwAsScriptRuntimeEx(e);
  }
}

代码示例来源:origin: rhino/js

/**
 * Return new {@link Scriptable} instance using the default
 * constructor for the class of the underlying Java method.
 * Return null to indicate that the call method should be used to create
 * new objects.
 */
@Override
public Scriptable createObject(Context cx, Scriptable scope) {
  if (member.isCtor() || parmsLength == VARARGS_CTOR) {
    return null;
  }
  Scriptable result;
  try {
    result = (Scriptable) member.getDeclaringClass().newInstance();
  } catch (Exception ex) {
    throw Context.throwAsScriptRuntimeEx(ex);
  }
  result.setPrototype(getClassPrototype());
  result.setParentScope(getParentScope());
  return result;
}

相关文章

微信公众号

Context类方法