com.google.gwt.core.client.JavaScriptException类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 JavaScript  
字(6.7k)|赞(0)|评价(0)|浏览(284)

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

JavaScriptException介绍

[英]Any JavaScript exceptions occurring within JSNI methods are wrapped as this class when caught in Java code. The wrapping does not occur until the exception passes out of JSNI into Java. Before that, the thrown object remains a native JavaScript exception object, and can be caught in JSNI as normal.

The return value of #getStackTrace() may vary between browsers due to variations in the underlying error-reporting capabilities. When possible, the stack trace will be the stack trace of the underlying error object. If it is not possible to accurately report a stack trace, a zero-length array will be returned. In those cases where the underlying stack trace cannot be determined, #fillInStackTrace() can be called in the associated catch block to create a stack trace corresponding to the location where the JavaScriptException object was created.

try { 
nativeMethod(); 
} catch (JavaScriptException e) { 
if (e.getStackTrace().length == 0) { 
e.fillInStackTrace(); 
} 
}

[中]在Java代码中捕获时,JSNI方法中发生的任何JavaScript异常都被包装为此类。直到异常从JSNI传递到Java中,包装才会发生。在此之前,抛出的对象仍然是一个本机JavaScript异常对象,可以在JSNI中正常捕获。
#getStackTrace()的返回值可能因浏览器而异,这是由于底层错误报告功能的不同。如果可能,堆栈跟踪将是底层错误对象的堆栈跟踪。如果无法准确报告堆栈跟踪,将返回零长度数组。在无法确定底层堆栈跟踪的情况下,可以在关联的catch块中调用#fillInStackTrace(),以创建与创建JavaScriptException对象的位置相对应的堆栈跟踪。

try { 
nativeMethod(); 
} catch (JavaScriptException e) { 
if (e.getStackTrace().length == 0) { 
e.fillInStackTrace(); 
} 
}

代码示例

代码示例来源:origin: com.google.gwt/gwt-servlet

private void setHeaders(XMLHttpRequest xmlHttpRequest)
   throws RequestException {
  if (headers != null && headers.size() > 0) {
   for (Map.Entry<String, String> header : headers.entrySet()) {
    try {
     xmlHttpRequest.setRequestHeader(header.getKey(), header.getValue());
    } catch (JavaScriptException e) {
     throw new RequestException(e.getMessage());
    }
   }
  } else {
   xmlHttpRequest.setRequestHeader("Content-Type",
     "text/plain; charset=utf-8");
  }
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

private void ensureInit() {
 if (message == null) {
  Object exception = getThrown();
  name = getExceptionName(exception);
  description = description + ": " + getExceptionDescription(exception);
  message = "(" + name + ") " + description;
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

@Override
public String getMessage() {
 ensureInit();
 return message;
}

代码示例来源:origin: org.codehaus.sonar/sonar-gwt-api

public static int getArraySize(JSONValue array) {
 if (array instanceof JSONArray) {
  return ((JSONArray) array).size();
 }
 if (array instanceof JSONObject) {
  return ((JSONObject) array).size();
 }
 throw new JavaScriptException("Not implemented");
}

代码示例来源:origin: com.google.gwt/gwt-servlet

private static native void reportToBrowser(Object e) /*-{
 $wnd.setTimeout(function () {
  throw e;
 }, 0);
}-*/;

代码示例来源:origin: threerings/playn

throw e;
} else {
 JavaScriptException materialized = new JavaScriptException(e.getName(),
   e.getDescription());
 materialized.setStackTrace(e.getStackTrace());
 throw materialized;

代码示例来源:origin: JetBrains/mapper

private void doExecute(Runnable r) {
 try {
  r.run();
 } catch (JavaScriptException jse) {
  if (jse.isThrownSet()) {
   LOG.severe("Caught JavaScriptException, wrapped error is: " + jse.getThrown());
  }
  ThrowableHandlers.handle(jse);
 } catch (Throwable t) {
  ThrowableHandlers.handle(t);
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

private static String getExceptionName(Object e) {
 if (e == null) {
  return "null";
 } else if (e instanceof JavaScriptObject) {
  return getExceptionName0((JavaScriptObject) e);
 } else if (e instanceof String) {
  return "String";
 } else {
  return e.getClass().getName();
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

private static String getExceptionDescription(Object e) {
 if (e instanceof JavaScriptObject) {
  return getExceptionDescription0((JavaScriptObject) e);
 } else {
  return e + "";
 }
}

代码示例来源:origin: com.allen-sauer.gwt.log/gwt-log

static JavaScriptException convertJavaScriptObjectToException(JavaScriptObject e) {
 return new JavaScriptException(javaScriptExceptionName(e), javaScriptExceptionDescription(e));
}

代码示例来源:origin: com.google.web.bindery/requestfactory-server

private static native void reportToBrowser(Object e) /*-{
 $wnd.setTimeout(function () {
  throw e;
 }, 0);
}-*/;

代码示例来源:origin: net.wetheinter/gwt-user

private static String getExceptionName(Object e) {
 if (e == null) {
  return "null";
 } else if (e instanceof JavaScriptObject) {
  return getExceptionName0((JavaScriptObject) e);
 } else if (e instanceof String) {
  return "String";
 } else {
  return e.getClass().getName();
 }
}

代码示例来源:origin: com.google.web.bindery/requestfactory-server

private static String getExceptionDescription(Object e) {
 if (e instanceof JavaScriptObject) {
  return getExceptionDescription0((JavaScriptObject) e);
 } else {
  return e + "";
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

RequestPermissionException requestPermissionException = new RequestPermissionException(
   url);
 requestPermissionException.initCause(new RequestException(e.getMessage()));
 throw requestPermissionException;
 xmlHttpRequest.send(requestData);
} catch (JavaScriptException e) {
 throw new RequestException(e.getMessage());

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

private void ensureInit() {
 if (message == null) {
  Object exception = getThrown();
  name = getExceptionName(exception);
  description = description + ": " + getExceptionDescription(exception);
  message = "(" + name + ") " + description;
 }
}

代码示例来源:origin: org.vectomatic/lib-gwt-svg

public OMSVGICCColor iccColor(String str) {
//        GWT.log("iccColor(" + str + ")");
    ICC.setLastIndex(0);
    MatchResult result = ICC.exec(str);
    if (result != null && result.getGroupCount() == 3) {
      String[] intArray = result.getGroup(2).split(COMMA);
      List<Integer> intList = new ArrayList<Integer>();
      for (int i = 0; i < intArray.length; i++) {
        if (intArray[i].length() > 0) {
          intList.add(Integer.parseInt(intArray[i]));
        }
      }
      return new OMSVGICCColor(result.getGroup(1), intList);
    }
    throw new JavaScriptException("Invalid icc-color spec: " + str);
  }

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Returns the original JavaScript message of the exception; may be
 * <code>null</code>.
 */
public String getDescription() {
 ensureInit();
 return description;
}

代码示例来源:origin: net.wetheinter/gwt-user

private static native void reportToBrowser(Object e) /*-{
 $wnd.setTimeout(function () {
  throw e;
 }, 0);
}-*/;

代码示例来源:origin: com.google.web.bindery/requestfactory-server

private static String getExceptionName(Object e) {
 if (e == null) {
  return "null";
 } else if (e instanceof JavaScriptObject) {
  return getExceptionName0((JavaScriptObject) e);
 } else if (e instanceof String) {
  return "String";
 } else {
  return e.getClass().getName();
 }
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

private static String getExceptionDescription(Object e) {
 if (e instanceof JavaScriptObject) {
  return getExceptionDescription0((JavaScriptObject) e);
 } else {
  return e + "";
 }
}

相关文章