use of org.graalvm.polyglot.PolyglotException.StackFrame in project graal by oracle.
the class SLExceptionTest method assertHostFrame.
private static void assertHostFrame(Iterator<StackFrame> frames, String className, String methodName) {
assertTrue(frames.hasNext());
StackFrame frame = frames.next();
assertTrue(frame.isHostFrame());
assertFalse(frame.isGuestFrame());
assertEquals("host", frame.getLanguage().getId());
assertEquals("Host", frame.getLanguage().getName());
assertEquals(className + "." + methodName, frame.getRootName());
assertNull(frame.getSourceLocation());
assertNotNull(frame.toString());
StackTraceElement hostFrame = frame.toHostFrame();
assertEquals(className, hostFrame.getClassName());
assertEquals(methodName, hostFrame.getMethodName());
assertNotNull(hostFrame.toString());
assertTrue(hostFrame.equals(hostFrame));
assertNotEquals(0, hostFrame.hashCode());
}
use of org.graalvm.polyglot.PolyglotException.StackFrame in project graal by oracle.
the class PolyglotExceptionImpl method materialize.
private void materialize() {
if (this.materializedFrames == null) {
List<StackFrame> frames = new ArrayList<>();
for (StackFrame frame : getPolyglotStackTrace()) {
frames.add(frame);
}
this.materializedFrames = Collections.unmodifiableList(frames);
}
}
use of org.graalvm.polyglot.PolyglotException.StackFrame in project graal by oracle.
the class ValueHostConversionTest method testExceptionFrames1.
@Test
public void testExceptionFrames1() {
Value innerInner = context.asValue(new Function<Object, Object>() {
public Object apply(Object t) {
throw new RuntimeException("foobar");
}
});
Value inner = context.asValue(new Function<Object, Object>() {
public Object apply(Object t) {
return innerInner.execute(t);
}
});
Value outer = context.asValue(new Function<Object, Object>() {
public Object apply(Object t) {
return inner.execute(t);
}
});
try {
outer.execute(1);
Assert.fail();
} catch (PolyglotException e) {
assertTrue(e.isHostException());
assertTrue(e.asHostException() instanceof RuntimeException);
assertEquals("foobar", e.getMessage());
Iterator<StackFrame> frameIterator = e.getPolyglotStackTrace().iterator();
StackFrame frame;
for (int i = 0; i < 3; i++) {
frame = frameIterator.next();
assertTrue(frame.isHostFrame());
assertEquals("apply", frame.toHostFrame().getMethodName());
frame = frameIterator.next();
assertTrue(frame.isHostFrame());
assertEquals("execute", frame.toHostFrame().getMethodName());
}
frame = frameIterator.next();
assertTrue(frame.isHostFrame());
assertEquals("testExceptionFrames1", frame.toHostFrame().getMethodName());
}
}
use of org.graalvm.polyglot.PolyglotException.StackFrame in project graal by oracle.
the class ValueHostConversionTest method testExceptionFrames3.
@Test
public void testExceptionFrames3() {
Value value = context.asValue(new TestExceptionFrames2());
TestExceptionFrames3 f = value.as(TestExceptionFrames3.class);
try {
f.foo();
Assert.fail();
} catch (PolyglotException e) {
assertTrue(e.isHostException());
assertTrue(e.asHostException() instanceof RuntimeException);
assertEquals("foo", e.getMessage());
Iterator<StackFrame> frameIterator = e.getPolyglotStackTrace().iterator();
StackFrame frame;
frame = frameIterator.next();
assertTrue(frame.isHostFrame());
assertEquals("foo", frame.toHostFrame().getMethodName());
frame = frameIterator.next();
assertTrue(frame.isHostFrame());
assertEquals("invoke", frame.toHostFrame().getMethodName());
frame = frameIterator.next();
assertTrue(frame.isHostFrame());
assertEquals("foo", frame.toHostFrame().getMethodName());
frame = frameIterator.next();
assertTrue(frame.isHostFrame());
assertEquals("testExceptionFrames3", frame.toHostFrame().getMethodName());
}
}
Aggregations