Class PolyglotException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.graalvm.polyglot.PolyglotException
- All Implemented Interfaces:
- Serializable
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:
- Guest Exception: Is- trueif the exception was raised in guest language code.
- Host Exception: Is- trueif this exception was raised in host runtime code. This may happen if the polyglot runtime host runtime methods that throw an exception. The original host exception can be accessed using- asHostException().
- Cancelled: Is- trueif the execution got cancelled. The execution may be cancelled when- closinga context, by a guest language intrinsic or by a tool, like the debugger.
- Exit: Is- trueif the execution exited. The guest language triggers exit events if the guest language code request to exit the VM. The exit status can be accessed using- getExitStatus().
- Syntax Error: Is- trueif the error represents a syntax error. For syntax errors a- locationmay be available.
- Incomplete Source: Is- trueif this returns a- syntax errorthat indicates that the source is incomplete.
- Resource exhausted: Is- trueif a resource limit e.g. the maximum memory was exhausted.
- Internal Error: Is- trueif an internal implementation error occurred in the polyglot runtime, the guest language or an instrument. It is not recommended to show such errors to the user in production. Please consider filing issues for internal implementation errors.
- Since:
- 19.0
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionfinal classRepresents a polyglot stack frame originating from a guest language or the host language Java.
- 
Method SummaryModifier and TypeMethodDescriptionReturns the original Java host exception that caused this exception.booleanUnsupported,PolyglotExceptioninstances are not writable therefore filling the stack trace has no effect for them.intReturns the exit status if this exception indicates that the application wasexited.Returns an additional guest language object.Gets a user readable message for the polyglot exception.Provides programmatic access to the polyglot stack trace information printed byprintStackTrace().Gets a guest language source location of this error ornullif no source location is available for this exception.Gets stack trace elements for Java and guest languages.inthashCode()booleanReturnstrueif the execution was cancelled.booleanisExit()Returnstrueif this exception is caused by an attempt of a guest language program to exit the application.booleanReturnstrueif this exception originates from a Graal guest language.booleanReturnstrueif this exception originates from the Java host language.booleanReturnstrueif this exception indicates a syntax error that is indicating that the syntax is incomplete.booleanReturnstrueif this exception was caused by an internal implementation error.booleanReturnstrueif the current application thread was interrupted by anInterruptedException, or by callingContext.interrupt(Duration)from the host.booleanReturnstrueif this exception indicates that a resource limit was exceeded, elsefalse.booleanReturnstrueif this exception indicates a parser or syntax error.voidPrints host and guest language stack frames to the standarderror output.voidPrints host and guest language stack frames to specified print stream.voidPrints host and guest language stack frames to specified print writer.voidsetStackTrace(StackTraceElement[] stackTrace) Unsupported,PolyglotExceptioninstances are not writable therefore setting the stack trace has no effect for them.toString()Returns a short description of this exception.Methods inherited from class ThrowableaddSuppressed, getCause, getLocalizedMessage, getSuppressed, initCause
- 
Method Details- 
toStringReturns a short description of this exception. The result is the concatenation of:- the qualified name of the metaobject of the guest exception, if this object represents
one, and it has a metaobject. Otherwise, the name of the
PolyglotExceptionclass.
- ": " (a colon and a space)
- the result of invoking this object's getMessage()method
 getMessagereturnsnull, then just the class name is returned.
- the qualified name of the metaobject of the guest exception, if this object represents
one, and it has a metaobject. Otherwise, the name of the
- 
printStackTracepublic void printStackTrace()Prints host and guest language stack frames to the standarderror output.- Overrides:
- printStackTracein class- Throwable
- Since:
- 19.0
 
- 
printStackTracePrints host and guest language stack frames to specified print stream.- Overrides:
- printStackTracein class- Throwable
- Since:
- 19.0
 
- 
printStackTracePrints host and guest language stack frames to specified print writer.- Overrides:
- printStackTracein class- Throwable
- Since:
- 19.0
 
- 
fillInStackTraceUnsupported,PolyglotExceptioninstances are not writable therefore filling the stack trace has no effect for them.- Overrides:
- fillInStackTracein class- Throwable
- Since:
- 19.0
 
- 
getStackTraceGets stack trace elements for Java and guest languages. For polyglot exceptions it recommended to usegetPolyglotStackTrace()as the guest language stack elements do not always fit the Java format for stack trace elements.- Overrides:
- getStackTracein class- Throwable
- Since:
- 19.0
 
- 
getMessageGets a user readable message for the polyglot exception. In case the exception isinternalthen the original java class name is included in the message. The message may returnnullif no message is available.- Overrides:
- getMessagein class- Throwable
- Since:
- 19.0
 
- 
getSourceLocationGets a guest language source location of this error ornullif no source location is available for this exception.- Since:
- 19.0
 
- 
equals
- 
hashCode
- 
setStackTraceUnsupported,PolyglotExceptioninstances are not writable therefore setting the stack trace has no effect for them.- Overrides:
- setStackTracein class- Throwable
- Since:
- 19.0
 
- 
getPolyglotStackTraceProvides programmatic access to the polyglot stack trace information printed byprintStackTrace(). 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.- Since:
- 19.0
- See Also:
 
- 
isHostExceptionpublic boolean isHostException()Returnstrueif this exception originates from the Java host language. In such a case the firststack framereturns ahost frameas zeroth element.- Since:
- 19.0
 
- 
isGuestExceptionpublic boolean isGuestException()Returnstrueif this exception originates from a Graal guest language. In such a case the firststack framereturns aguest frameas zeroth element.- Since:
- 19.0
 
- 
asHostExceptionReturns 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 thepolyglot stack trace.- Throws:
- UnsupportedOperationException- if this exception is not a host exception. Call- isHostException()to ensure its originating from the host language.
- Since:
- 19.0
 
- 
isInternalErrorpublic boolean isInternalError()Returnstrueif 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
 
- 
isResourceExhaustedpublic boolean isResourceExhausted()Returnstrueif this exception indicates that a resource limit was exceeded, elsefalse. 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
OutOfMemoryErrororStackOverflowError, then they will be translated to aPolyglotExceptionthat returntrueforisResourceExhausted().
- A configured resource limitwas 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 hostorguest. Resource limit exceeded errors are neverinternal, but may have caused the context to becancelledsuch that it is no longer usable.- Since:
- 20.2
 
- The host runtime run out of memory or stack space. For example if host runtime throws
- 
isCancelledpublic boolean isCancelled()Returnstrueif the execution was cancelled. The execution can be cancelled byclosinga context, if an instrument such as a debugger decides to cancel the current execution or if aresource limitwas exceeded. The context that caused a cancel event becomes unusable, i.e. closed.- Since:
- 19.0
 
- 
isInterruptedpublic boolean isInterrupted()Returnstrueif the current application thread was interrupted by anInterruptedException, or by callingContext.interrupt(Duration)from the host.- Since:
- 20.3
 
- 
isExitpublic boolean isExit()Returnstrueif this exception is caused by an attempt of a guest language program to exit the application. The provided exit code can be accessed usinggetExitStatus(). This can be the result of either the soft or the hard exit.- Since:
- 19.0
- See Also:
 
- 
isSyntaxErrorpublic boolean isSyntaxError()Returnstrueif this exception indicates a parser or syntax error. In such a case #get- Since:
- 19.0
 
- 
isIncompleteSourcepublic boolean isIncompleteSource()Returnstrueif 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 returnstrue.- Since:
- 19.0
 
- 
getGuestObjectReturns an additional guest language object. Returnsnullif no exception object is available.- Since:
- 19.0
 
- 
getExitStatuspublic int getExitStatus()Returns the exit status if this exception indicates that the application wasexited. The exit status is intended to be passed toSystem.exit(int). In case of hard exit the application can be configured to callSystem.exit(int)directly usingContext.Builder.useSystemExit(boolean).- Since:
- 19.0
- See Also:
 
 
-