org.mozilla.javascript.EcmaError类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 JavaScript  
字(7.7k)|赞(0)|评价(0)|浏览(1051)

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

EcmaError介绍

[英]The class of exceptions raised by the engine as described in ECMA edition 3. See section 15.11.6 in particular.
[中]ECMA第3版中描述的引擎引发的异常类别。具体见第15.11.6节。

代码示例

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

/**
 * @deprecated Use {@link RhinoException#lineNumber()} from the super class.
 */
public int getLineNumber()
{
  return lineNumber();
}

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

/**
 * @deprecated Use {@link RhinoException#sourceName()} from the super class.
 */
public String getSourceName()
{
  return sourceName();
}

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

/**
 * @deprecated
 * Use {@link RhinoException#columnNumber()} from the super class.
 */
public int getColumnNumber() {
  return columnNumber();
}

代码示例来源:origin: org.apache.cocoon/cocoon-flowscript-impl

public Location getLocation(Object obj, String description) {
    if (obj instanceof EcmaError) {
      EcmaError ex = (EcmaError)obj;
      if (ex.sourceName() != null) {
        return new LocationImpl(ex.getName(), ex.sourceName(), ex.lineNumber(), ex.columnNumber());
      } else {
        return Location.UNKNOWN;
      }

    } else if (obj instanceof JavaScriptException) {
      JavaScriptException ex = (JavaScriptException)obj;
      if (ex.sourceName() != null) {
        return new LocationImpl(description, ex.sourceName(), ex.lineNumber(), -1);
      } else {
        return Location.UNKNOWN;
      }
    }
    
    return null;
  } 
};

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

EcmaError ee = (EcmaError)t;
  re = ee;
  errorName = ee.getName();
  errorMsg = ee.getErrorMessage();
} else if (t instanceof WrappedException) {
  WrappedException we = (WrappedException)t;

代码示例来源:origin: alexo/wro4j

/**
 * Creates a more detailed message based on {@link RhinoException} thrown by rhino execution. The message will contain
 * a detailed description of the problem by inspecting the JSON value provided by exception.
 * 
 * @param e
 *          {@link RhinoException} thrown by rhino execution.
 * @return detailed string message.
 */
public static String createExceptionMessage(final RhinoException e) {
 StringBuffer message = new StringBuffer("Could not execute the script because: \n");
 if (e instanceof JavaScriptException) {
  message.append(toJson(((JavaScriptException) e).getValue()));
 } else if (e instanceof EcmaError) {
  final EcmaError ecmaError = (EcmaError) e;
  message.append(String.format("Error message: %s at line: %s. \nSource: %s", ecmaError.getErrorMessage(),
    ecmaError.lineNumber(), ecmaError.lineSource()));
 } else {
  message.append(e.getMessage());
 }
 return message.toString();
}

代码示例来源:origin: org.geoserver.script/gs-script-js

@Override
public Object eval(Reader reader, ScriptContext context) throws ScriptException {
  String filename = (String) get(ScriptEngine.FILENAME);
  if (filename == null) {
    filename = "<Unknown Source>";
  }
  Object result;
  EngineScope scope = new EngineScope(context);
  Global global = getGlobal();
  scope.setParentScope(global);
  scope.setPrototype(global);
  Context cx = enterContext();
  try {
    scope.put("exports", scope, cx.newObject(global));
    result = cx.evaluateReader(scope, reader, filename, 1, null);
  } catch (EcmaError e) {
    throw new ScriptException(
        e.getMessage(), e.sourceName(), e.lineNumber(), e.columnNumber());
  } catch (Exception e) {
    throw new ScriptException(e);
  } finally {
    Context.exit();
  }
  return result;
}

代码示例来源:origin: ca.carleton.gcrc/nunaliit2-javascript

public Object evaluateJavascript(String javascript) throws Exception {
  try {
    Object result = cx.evaluateString(scope, javascript, "main", 1, null);
    return result;
    
  } catch(EcmaError e) {
    for(JavascriptRunnerListener listener : listeners){
      listener.runtimeError(e.details(), e.sourceName(), e.lineNumber());
    }
    throw e;
  }
}

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

public static EcmaError constructError(String error,
                    String message,
                    String sourceName,
                    int lineNumber,
                    String lineSource,
                    int columnNumber)
{
  return new EcmaError(error, message, sourceName,
             lineNumber, lineSource, columnNumber);
}

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

/**
 * @deprecated Use {@link RhinoException#lineSource()} from the super class.
 */
public String getLineSource() {
  return lineSource();
}

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

/**
 * Create an exception with the specified detail message.
 *
 * Errors internal to the JavaScript engine will simply throw a
 * RuntimeException.
 *
 * @param sourceName the name of the source responsible for the error
 * @param lineNumber the line number of the source
 * @param columnNumber the columnNumber of the source (may be zero if
 *                     unknown)
 * @param lineSource the source of the line containing the error (may be
 *                   null if unknown)
 */
EcmaError(String errorName, String errorMessage,
     String sourceName, int lineNumber,
     String lineSource, int columnNumber)
{
  recordErrorOrigin(sourceName, lineNumber, lineSource, columnNumber);
  this.errorName = errorName;
  this.errorMessage = errorMessage;
}

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

static boolean accept(Object nameObj) {
  String name;
  try {
    name = ScriptRuntime.toString(nameObj);
  } catch (EcmaError ee) {
    if ("TypeError".equals(ee.getName())) {
      return false;
    }
    throw ee;
  }
  // See http://w3.org/TR/xml-names11/#NT-NCName
  int length = name.length();
  if (length != 0) {
    if (isNCNameStartChar(name.charAt(0))) {
      for (int i = 1; i != length; ++i) {
        if (!isNCNameChar(name.charAt(i))) {
          return false;
        }
      }
      return true;
    }
  }
  return false;
}

代码示例来源:origin: couchbase/CouchbaseMock

} catch (EcmaError ex2) {
  throw new QueryExecutionException(ex2.getErrorMessage());
throw new QueryExecutionException(parseErr.getErrorMessage());

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

EcmaError ee = (EcmaError)t;
  re = ee;
  errorName = ee.getName();
  errorMsg = ee.getErrorMessage();
} else if (t instanceof WrappedException) {
  WrappedException we = (WrappedException)t;

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

/**
 * Creates a more detailed message based on {@link RhinoException} thrown by rhino execution. The message will contain
 * a detailed description of the problem by inspecting the JSON value provided by exception.
 * 
 * @param e
 *          {@link RhinoException} thrown by rhino execution.
 * @return detailed string message.
 */
public static String createExceptionMessage(final RhinoException e) {
 StringBuffer message = new StringBuffer("Could not execute the script because: \n");
 if (e instanceof JavaScriptException) {
  message.append(toJson(((JavaScriptException) e).getValue()));
 } else if (e instanceof EcmaError) {
  final EcmaError ecmaError = (EcmaError) e;
  message.append(String.format("Error message: %s at line: %s. \nSource: %s", ecmaError.getErrorMessage(),
    ecmaError.lineNumber(), ecmaError.lineSource()));
 } else {
  message.append(e.getMessage());
 }
 return message.toString();
}

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

public static EcmaError constructError(String error,
                    String message,
                    String sourceName,
                    int lineNumber,
                    String lineSource,
                    int columnNumber)
{
  return new EcmaError(error, message, sourceName,
             lineNumber, lineSource, columnNumber);
}

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

/**
 * @deprecated Use {@link RhinoException#lineSource()} from the super class.
 */
public String getLineSource() {
  return lineSource();
}

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

/**
 * Create an exception with the specified detail message.
 *
 * Errors internal to the JavaScript engine will simply throw a
 * RuntimeException.
 *
 * @param sourceName the name of the source responsible for the error
 * @param lineNumber the line number of the source
 * @param columnNumber the columnNumber of the source (may be zero if
 *                     unknown)
 * @param lineSource the source of the line containing the error (may be
 *                   null if unknown)
 */
EcmaError(String errorName, String errorMessage,
     String sourceName, int lineNumber,
     String lineSource, int columnNumber)
{
  recordErrorOrigin(sourceName, lineNumber, lineSource, columnNumber);
  this.errorName = errorName;
  this.errorMessage = errorMessage;
}

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

static boolean accept(Object nameObj) {
  String name;
  try {
    name = ScriptRuntime.toString(nameObj);
  } catch (EcmaError ee) {
    if ("TypeError".equals(ee.getName())) {
      return false;
    }
    throw ee;
  }
  
  // See http://w3.org/TR/xml-names11/#NT-NCName
  int length = name.length();
  if (length != 0) {
    if (isNCNameStartChar(name.charAt(0))) {
      for (int i = 1; i != length; ++i) {
        if (!isNCNameChar(name.charAt(i))) {
          return false;
        }
      }
      return true;
    }
  }
  
  return false;
}

代码示例来源:origin: com.couchbase.mock/CouchbaseMock

} catch (EcmaError ex2) {
  throw new QueryExecutionException(ex2.getErrorMessage());
throw new QueryExecutionException(parseErr.getErrorMessage());

相关文章