package jetbrains.mps.debugger.java.api.evaluation; /*Generated by MPS */ import org.apache.log4j.Logger; import org.apache.log4j.LogManager; import org.jetbrains.annotations.NotNull; import com.sun.jdi.InvocationException; import org.jetbrains.annotations.Nullable; import com.sun.jdi.ThreadReference; import jetbrains.mps.debugger.java.api.evaluation.proxies.IObjectValueProxy; import jetbrains.mps.debugger.java.api.evaluation.proxies.MirrorUtil; import jetbrains.mps.debugger.java.api.evaluation.proxies.IArrayValueProxy; /** * Wraps com.sun.jdi.InvocationException. * Thrown to indicate an exception occurred in an invoked method within the target VM. */ public class TargetVMEvaluationException extends EvaluationException { private static final Logger LOG = LogManager.getLogger(TargetVMEvaluationException.class); public TargetVMEvaluationException(@NotNull InvocationException e) { this(e, null); } public TargetVMEvaluationException(@NotNull InvocationException e, @Nullable ThreadReference threadReference) { super(e.exception().referenceType().name()); if (threadReference == null) { return; } try { IObjectValueProxy exceptionProxy = (IObjectValueProxy) MirrorUtil.getInstance().getValueProxy(e.exception()); IArrayValueProxy stackTrace = (IArrayValueProxy) exceptionProxy.invokeMethod("getStackTrace", "()[Ljava/lang/StackTraceElement;", threadReference); int length = stackTrace.getLength(); StackTraceElement[] newStackTrace = new StackTraceElement[length]; for (int i = 0; i < length; i++) { IObjectValueProxy stackTraceElement = (IObjectValueProxy) stackTrace.getElementAt(i); newStackTrace[i] = new StackTraceElement((String) stackTraceElement.getFieldValue("declaringClass").getJavaValue(), (String) stackTraceElement.getFieldValue("methodName").getJavaValue(), (String) stackTraceElement.getFieldValue("fileName").getJavaValue(), (Integer) stackTraceElement.getFieldValue("lineNumber").getJavaValue()); } setStackTrace(newStackTrace); } catch (ClassCastException exception) { LOG.warn("Cant create TargetVMEvaluationException for " + e, exception); } catch (EvaluationException exception) { LOG.warn("Cant create TargetVMEvaluationException for " + e, exception); } } }