rJava (version 0.4-9)

jcheck: Check JVM for pending expections and clear them

Description

.jcheck checks the Java VM for any pending exceptions and clears them.

Usage

.jcheck(silent = FALSE)

Arguments

silent
If set to FALSE then Java is instructed to print the exception on stderr. Note that Windows Rgui doesn't show stderr so it will not appear there (the printing is done internally in the JVM, so there is no

Value

  • Returns TRUE if an exception occurred or FALSE otherwise.

Details

The exception handling is currently rather crude as there is no way to obtain programmatical access to thrown exceptions. In addition, some internal code clears exceptions (e.g. after some failed JNI calls), so it may occasionally not behave as expected. However, this applies only to code called as a side-effect (such as when converting an object), so exceptions thrown as a result of a directly invoked code are not affected.

Nevertheless more elaborate exception handling system is planned for rJava 0.5.

See Also

.jcall

Examples

Run this code
# we try to create a bogus object and
# instruct .jnew to not clear the exception
v <- .jnew("foo/bar", check=FALSE)

# expect TRUE result here because the class doesn't exist
print(.jcheck(silent=TRUE))
# next invocation will be FALSE because the exception is now cleared
print(.jcheck(silent=TRUE))

Run the code above in your browser using DataCamp Workspace