jcheck(rJava)
jcheck()所属R语言包:rJava
Java exception handling
Java异常处理
译者:生物统计家园网 机器人LoveR
描述----------Description----------
.jcheck checks the Java VM for any pending exceptions and clears them.
.jcheck检查任何未决的例外Java VM和清除它们。
.jthrow throws a Java exception.
.jthrow抛出一个Java异常。
.jgetEx polls for any pending expections and returns the exception object.
.jgetEx民调任何悬而未决expections和返回异常对象。
.jclear clears a pending exception.
.jclear清除挂起的异常。
用法----------Usage----------
.jcheck(silent = FALSE)
.jthrow(exception, message = NULL)
.jgetEx(clear = FALSE)
.jclear()
参数----------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 (as of rJava 0.5-1 some errors that the JVM prints using the vfprintf callback are passed to R. However, some parts are printed using System.err in which case the ususal redirection using the System class can be used by the user).
如果设置为FALSE然后Java的指示到打印stderr的异常。请注意,Windows的Rgui不显示stderr所以不会出现(,作为rJava 0.5-1一些错误,JVM打印使用vfprintf回调,被传递到R然而,一些地方使用<打印X>在这种情况下,使用ususal重定向System.err类可以由用户使用)。
参数:exception
is either a class name of an exception to create or a throwable object reference that is to be thrown.
要么是一个例外创建或抛出一个Throwable对象的引用的类名。
参数:message
if exception is a class name then this parameter specifies the string to be used as the message of the exception. This parameter is ignored if exception is a reference.
如果exception是一个类名,那么这个参数指定要使用的字符串作为异常消息。 exception如果是一个参考,这个参数将被忽略。
参数:clear
if set to TRUE then the returned exception is also cleared, otherwise the throwable is returned without clearing the cause.
如果设置为TRUE然后返回的异常也被清除,否则不清除的原因返回的throwable。
Details
详情----------Details----------
Please note that some functions (such as .jnew or .jcall) call .jcheck implicitly unless instructed to not do so. If you want to handle Java exceptions, you should make sure that those function don't clear the exception you may want to catch.
请注意,某些功能(如.jnew或.jcall)调用.jcheck含蓄,除非不这样做。如果你想处理Java异常,你应该确保那些功能不清除的异常,你可能想赶上。
The exception handling is still as a very low-level and experimental, because it requires polling of exceptions. A more elaboate system using constructs similar to try ... catch is planned for next major version of rJava.
异常处理仍然是一个非常低的水平和实验,因为它需要轮询例外。一个更elaboate的系统,使用结构类似try... catch计划下的主要版本rJava。
Warning: When requesting exceptions to not be cleared automatically, please note that the show method (which is called by print) has a side-effect of making a Java call to get the string representation of a Java object. This implies that it will be impeded by any pending exceptions. Therefore exceptions obtained through .jgetEx can be stored, but should not be printed (or otherwise used in Java calls) until after the exception is cleared. In general, all Java calls will fail (possibly silently) until the exception is cleared.
警告:要求不能自动清除的异常时,请注意,show方法(称为print)有一个Java调用一个Java的字符串表示的副作用。对象。这意味着,这将是阻碍任何悬而未决的例外。因此,通过.jgetEx得到的异常可以存储,但不应印,直到异常被清除后(或以其他方式使用Java调用)。在一般情况下,所有的Java调用会失败(可能是默默的),直到异常被清除。
值----------Value----------
.jcheck returns TRUE if an exception occurred or FALSE otherwise.
.jcheck返回TRUE如果发生异常或FALSE否则。
.jgetEx returns NULL if there are no pending exceptions or an object of the class "java.lang.Throwable" representing the current exception.
.jgetEx返回NULL如果有没有未处理的异常或类“java.lang.Throwable的”代表当前异常对象。
参见----------See Also----------
.jcall, .jnew
.jcall,.jnew
举例----------Examples----------
# we try to create a bogus object and[我们尝试创建一个假的对象,]
# instruct .jnew to not clear the exception[指示。jnew不清除异常]
# this will raise an exception[这将引发异常]
v <- .jnew("foo/bar", check=FALSE)
# you can poll for the exception, but don't try to print it[你可以查询异常,但不要试图打印]
# (see details above)[(见上述资料)]
if (!is.null(e<-.jgetEx())) print("Java exception was raised")
# expect TRUE result here because the exception was still not cleared[预期结果为TRUE,因为仍然没有清除异常]
print(.jcheck(silent=TRUE))
# next invocation will be FALSE because the exception is now cleared[下次调用将是错误的,因为现在清除异常]
print(.jcheck(silent=TRUE))
# now you can print the actual expection (even after it was cleared)[现在你可以打印的实际expection(甚至被清除后,)]
print(e)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|