Top Description Inners Fields Constructors Methods
org.graalvm.polyglot

public final Class PolyglotException

extends RuntimeException
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, .NotSerializableException, .ObjectOutputStream, .PrintStream, .PrintWriter, java.time.Duration, org.graalvm.polyglot.impl.AbstractPolyglotImpl.AbstractExceptionDispatch, .AbstractPolyglotImpl.AbstractStackFrameImpl

A polyglot exception represents errors that contain Graal guest languages on the stack trace. In addition to the Java stack trace it also returns a polyglot stack trace. Methods like printStackTrace() are implemented such that host and guest language stack traces are printed nicely.

A polyglot exception may have the following properties:

Since
19.0
See Also
Context, Value

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
PolyglotException.StackFrame

Represents a polyglot stack frame originating from a guest language or the host language Java.

Field Summary

Modifier and TypeField and Description
pack-priv final AbstractPolyglotImpl.AbstractExceptionDispatch
pack-priv final Object

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Throwable
asHostException()

Returns the original Java host exception that caused this exception.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public Throwable
fillInStackTrace()

Overrides java.lang.Throwable.fillInStackTrace.

Unsupported, PolyglotException instances are not writable therefore filling the stack trace has no effect for them.

public int
getExitStatus()

Returns the exit status if this exception indicates that the application was exited.

public Value
getGuestObject()

Returns an additional guest language object.

public String
getMessage()

Overrides java.lang.Throwable.getMessage.

Gets a user readable message for the polyglot exception.

public Iterable<PolyglotException.StackFrame>
getPolyglotStackTrace()

Provides programmatic access to the polyglot stack trace information printed by printStackTrace().

public SourceSection
getSourceLocation()

Gets a guest language source location of this error or null if no source location is available for this exception.

public StackTraceElement[]
getStackTrace()

Overrides java.lang.Throwable.getStackTrace.

Gets stack trace elements for Java and guest languages.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
isCancelled()

Returns true if the execution was cancelled.

public boolean
isExit()

Returns true if this exception is caused by an attempt of a guest language program to exit the application.

public boolean
isGuestException()

Returns true if this exception originates from a Graal guest language.

public boolean
isHostException()

Returns true if this exception originates from the Java host language.

public boolean
isIncompleteSource()

Returns true if this exception indicates a syntax error that is indicating that the syntax is incomplete.

public boolean
isInternalError()

Returns true if this exception was caused by an internal implementation error.

public boolean
isInterrupted()

Returns true if the current application thread was interrupted by an InterruptedException, or by calling Context#interrupt(Duration) from the host.

public boolean
isResourceExhausted()

Returns true if this exception indicates that a resource limit was exceeded, else false.

public boolean
isSyntaxError()

Returns true if this exception indicates a parser or syntax error.

public void
printStackTrace()

Overrides java.lang.Throwable.printStackTrace.

Prints host and guest language stack frames to the standard error output.

public void
printStackTrace(PrintStream
PrintStream to use for output
s
)

Overrides java.lang.Throwable.printStackTrace.

Prints host and guest language stack frames to specified print stream.

public void
printStackTrace(PrintWriter
PrintWriter to use for output
s
)

Overrides java.lang.Throwable.printStackTrace.

Prints host and guest language stack frames to specified print writer.

public void
setStackTrace(StackTraceElement[]
the stack trace elements to be associated with this Throwable. The specified array is copied by this call; changes in the specified array after the method invocation returns will have no effect on this Throwable's stack trace.
stackTrace
)

Overrides java.lang.Throwable.setStackTrace.

Unsupported, PolyglotException instances are not writable therefore setting the stack trace has no effect for them.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
outputStream
)

Hides java.lang.Throwable.writeObject.

Write a Throwable object to a stream.

Field Detail

dispatchback to summary
pack-priv final AbstractPolyglotImpl.AbstractExceptionDispatch dispatch
implback to summary
pack-priv final Object impl

Constructor Detail

PolyglotExceptionback to summary
pack-priv PolyglotException(String message, AbstractPolyglotImpl.AbstractExceptionDispatch dispatch, Object receiver)

Method Detail

asHostExceptionback to summary
public Throwable asHostException()

Returns the original Java host exception that caused this exception. The original host exception contains a stack trace that is hardly interpretable by users as it contains details of the language implementation. The polyglot exception provides information for user-friendly error reporting with the polyglot stack trace.

Exceptions
UnsupportedOperationException:
if this exception is not a host exception. Call isHostException() to ensure its originating from the host language.
Since
19.0
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
Since
19.0
fillInStackTraceback to summary
public Throwable fillInStackTrace()

Overrides java.lang.Throwable.fillInStackTrace.

Unsupported, PolyglotException instances are not writable therefore filling the stack trace has no effect for them.

Returns:Throwable

Doc from java.lang.Throwable.fillInStackTrace.

a reference to this Throwable instance.

Annotations
@SuppressWarnings:sync-override
@Override
Since
19.0
getExitStatusback to summary
public int getExitStatus()

Returns the exit status if this exception indicates that the application was exited. The exit status is intended to be passed to System#exit(int). In case of hard exit the application can be configured to call System#exit(int) directly using Context.Builder#useSystemExit(boolean).

Since
19.0
See Also
Context
getGuestObjectback to summary
public Value getGuestObject()

Returns an additional guest language object. Returns null if no exception object is available.

Since
19.0
getMessageback to summary
public String getMessage()

Overrides java.lang.Throwable.getMessage.

Gets a user readable message for the polyglot exception. In case the exception is internal then the original java class name is included in the message. The message never returns null.

Returns:String

Doc from java.lang.Throwable.getMessage.

the detail message string of this Throwable instance (which may be null).

Annotations
@Override
Since
19.0
getPolyglotStackTraceback to summary
public Iterable<PolyglotException.StackFrame> getPolyglotStackTrace()

Provides programmatic access to the polyglot stack trace information printed by printStackTrace(). Returns an array of stack trace elements, each representing one stack frame. The zeroth element of the array (assuming the array's length is non-zero) represents the top of the stack, which is the last invocation in the sequence. Typically, this is the point at which this throwable was created and thrown. The last element of the array (assuming the array's length is non-zero) represents the bottom of the stack, which is the first method invocation in the sequence.

Annotations
@SuppressWarnings:unchecked
Since
19.0
See Also
StackFrame
getSourceLocationback to summary
public SourceSection getSourceLocation()

Gets a guest language source location of this error or null if no source location is available for this exception.

Since
19.0
getStackTraceback to summary
public StackTraceElement[] getStackTrace()

Overrides java.lang.Throwable.getStackTrace.

Gets stack trace elements for Java and guest languages. For polyglot exceptions it recommended to use getPolyglotStackTrace() as the guest language stack elements do not always fit the Java format for stack trace elements.

Returns:StackTraceElement[]

Doc from java.lang.Throwable.getStackTrace.

an array of stack trace elements representing the stack trace pertaining to this throwable.

Annotations
@Override
Since
19.0
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
Since
19.0
isCancelledback to summary
public boolean isCancelled()

Returns true if the execution was cancelled. The execution can be cancelled by closing a context, if an instrument such as a debugger decides to cancel the current execution or if a resource limit was exceeded. The context that caused a cancel event becomes unusable, i.e. closed.

Since
19.0
isExitback to summary
public boolean isExit()

Returns true if this exception is caused by an attempt of a guest language program to exit the application. The provided exit code can be accessed using getExitStatus(). This can be the result of either the soft or the hard exit.

Since
19.0
See Also
Context
isGuestExceptionback to summary
public boolean isGuestException()

Returns true if this exception originates from a Graal guest language. In such a case the first stack frame returns a guest frame as zeroth element.

Since
19.0
isHostExceptionback to summary
public boolean isHostException()

Returns true if this exception originates from the Java host language. In such a case the first stack frame returns a host frame as zeroth element.

Since
19.0
isIncompleteSourceback to summary
public boolean isIncompleteSource()

Returns true if this exception indicates a syntax error that is indicating that the syntax is incomplete. This allows guest language programmers to find out if more code is expected from a given source. For example, an incomplete JavaScript program could look like this:

function incompleteFunction(arg) {
A shell might react to this exception and prompt for additional source code, if this method returns true.
Since
19.0
isInternalErrorback to summary
public boolean isInternalError()

Returns true if this exception was caused by an internal implementation error. These errors should be reported as bugs if observed. Internal error messages are typically hard to understand for guest language programmers and might contain implementation specific details that allows guest language implementers to debug the problem.

Since
19.0
isInterruptedback to summary
public boolean isInterrupted()

Returns true if the current application thread was interrupted by an InterruptedException, or by calling Context#interrupt(Duration) from the host.

Since
20.3
isResourceExhaustedback to summary
public boolean isResourceExhausted()

Returns true if this exception indicates that a resource limit was exceeded, else false. Resource limit exceeded errors may be raised for the following reasons:

  • The host runtime run out of memory or stack space. For example if host runtime throws OutOfMemoryError or StackOverflowError, then they will be translated to a PolyglotException that return true for isResourceExhausted().
  • A configured resource limit was exceeded.
  • A runtime specific per context resource limit was exceeded. Depending on the host runtime implementation additional options to restrict the resource usage of a context may be specified using options.

Resource limit exceptions may be originating from the host or guest. Resource limit exceeded errors are never internal, but may have caused the context to be cancelled such that it is no longer usable.

Since
20.2
isSyntaxErrorback to summary
public boolean isSyntaxError()

Returns true if this exception indicates a parser or syntax error. In such a case #get

Since
19.0
printStackTraceback to summary
public void printStackTrace()

Overrides java.lang.Throwable.printStackTrace.

Prints host and guest language stack frames to the standard error output.

Annotations
@Override
Since
19.0
printStackTraceback to summary
public void printStackTrace(PrintStream s)

Overrides java.lang.Throwable.printStackTrace.

Prints host and guest language stack frames to specified print stream.

Parameters
s:PrintStream

Doc from java.lang.Throwable.printStackTrace.

PrintStream to use for output

Annotations
@Override
Since
19.0
printStackTraceback to summary
public void printStackTrace(PrintWriter s)

Overrides java.lang.Throwable.printStackTrace.

Prints host and guest language stack frames to specified print writer.

Parameters
s:PrintWriter

Doc from java.lang.Throwable.printStackTrace.

PrintWriter to use for output

Annotations
@Override
Since
19.0
setStackTraceback to summary
public void setStackTrace(StackTraceElement[] stackTrace)

Overrides java.lang.Throwable.setStackTrace.

Unsupported, PolyglotException instances are not writable therefore setting the stack trace has no effect for them.

Parameters
stackTrace:StackTraceElement[]

Doc from java.lang.Throwable.setStackTrace.

the stack trace elements to be associated with this Throwable. The specified array is copied by this call; changes in the specified array after the method invocation returns will have no effect on this Throwable's stack trace.

Annotations
@Override
Since
19.0
writeObjectback to summary
private void writeObject(ObjectOutputStream outputStream) throws IOException

Hides java.lang.Throwable.writeObject.

Doc from java.lang.Throwable.writeObject.

Write a Throwable object to a stream. A null stack trace field is represented in the serial form as a one-element array whose element is equal to new StackTraceElement("", "", null, Integer.MIN_VALUE).

Parameters
outputStream:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@SuppressWarnings:static-method, unused
Exceptions
IOException:
if an I/O error occurs
org.graalvm.polyglot back to summary

public final Class PolyglotException.StackFrame

extends Object
Class Inheritance

Represents a polyglot stack frame originating from a guest language or the host language Java.
Since
19.0

Field Summary

Modifier and TypeField and Description
pack-priv final AbstractPolyglotImpl.AbstractStackFrameImpl

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
getBytecodeIndex()

Returns the bytecode index of this frame if available, or a negative number if no bytecode index is available.

public Language
getLanguage()

Returns the language of this stack frame.

public String
getRootName()

Returns the root name of this stack frame.

public SourceSection
getSourceLocation()

Returns the source location of the stack frame or null if no source location is available.

public boolean
isGuestFrame()

Returns true if the stack frame originates from the guest language.

public boolean
isHostFrame()

Returns true if the stack frame originates from the host language.

public StackTraceElement
toHostFrame()

Returns a Java stack trace element representation of the polyglot stack trace element.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of this stack frame.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

implback to summary
pack-priv final AbstractPolyglotImpl.AbstractStackFrameImpl impl

Constructor Detail

StackFrameback to summary
pack-priv StackFrame(AbstractPolyglotImpl.AbstractStackFrameImpl impl)

Method Detail

getBytecodeIndexback to summary
public int getBytecodeIndex()

Returns the bytecode index of this frame if available, or a negative number if no bytecode index is available. The bytecode index is an internal identifier of the current execution location. The bytecode index is typically only provided by languages that are internally implemented as bytecode interpreter. This information is exposed for debugging or testing purposes and should not be relied upon for anything else.

Since
24.1
getLanguageback to summary
public Language getLanguage()

Returns the language of this stack frame. In case of the host language a synthetic Java language object is returned.

Since
19.0
getRootNameback to summary
public String getRootName()

Returns the root name of this stack frame. In case of the host language the Java method name is returned. In guest languages it returns a useful identifier for code. For example, in JavaScript this can be the function name.

Since
19.0
getSourceLocationback to summary
public SourceSection getSourceLocation()

Returns the source location of the stack frame or null if no source location is available. Host frames do never provide a source location.

Since
19.0
isGuestFrameback to summary
public boolean isGuestFrame()

Returns true if the stack frame originates from the guest language.

Since
19.0
isHostFrameback to summary
public boolean isHostFrame()

Returns true if the stack frame originates from the host language. Host frames do not provide a source location. Instead the Java stack frame can be accessed using toHostFrame().

Since
19.0
toHostFrameback to summary
public StackTraceElement toHostFrame()

Returns a Java stack trace element representation of the polyglot stack trace element. This is supported for host stack frames as well as guest language stack frames. A conversion to the host frame format can be useful for interoperability.

Since
19.0
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this stack frame. The format is inspired by the Java stack frame format.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override
Since
19.0