code: public static RuntimeException throwAsScriptRuntimeEx(Throwable e)
      {
          while ((e instanceof InvocationTargetException)) {
              e = ((InvocationTargetException) e).getTargetException();
          }
          // special handling of Error so scripts would not catch them
          if (e instanceof Error) {
              Context cx = getContext();
              if (cx == null ||
                  !cx.hasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS))
              {
                  throw (Error)e;
              }
          }
          if (e instanceof RhinoException) {
              throw (RhinoException)e;
          }
          throw new WrappedException(e);
      }
docs: Rethrow the exception wrapping it as the script runtime exception.
  Unless the exception is instance of {@link EcmaError} or
  {@link EvaluatorException} it will be wrapped as
  {@link WrappedException}, a subclass of {@link EvaluatorException}.
  The resulting exception object always contains
  source name and line number of script that triggered exception.
  <p>
  This method always throws an exception, its return value is provided
  only for convenience to allow a usage like:
  <pre>
  throw Context.throwAsScriptRuntimeEx(ex);
  </pre>
  to indicate that code after the method is unreachable.
  @throws EvaluatorException
  @throws EcmaError