File: exceptions.R

package info (click to toggle)
rjava 1.0-11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,184 kB
  • sloc: java: 13,223; ansic: 5,479; sh: 3,776; xml: 325; makefile: 250; perl: 33
file content (48 lines) | stat: -rw-r--r-- 1,012 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## functions for some basic exception handling

# FIXME: should all these actually be deprecated or defunct

## poll for an exception
.jgetEx <- function(clear=FALSE) {
  exo <- .Call(RpollException)
  if (is.null(exo)) return(NULL)
  x <- new("jobjRef", jobj=exo, jclass="java/lang/Throwable")
  if (clear) .jclear()
  x
}

## explicitly clear any pending exceptions
.jclear <- function() {
  .C(RclearException)
  invisible(NULL)
}

## throw an exception
.jthrow <- function(exception, message=NULL) {
  if (is.character(exception))
    exception <- .jnew(exception, as.character(message))
  if (is(exception, "jobjRef"))
    .Call(RthrowException, exception)
  else
    stop("Invalid exception.")
}


"$.Throwable" <- function( x, name ){
	if( name %in% names(c(x)) ){
		c(x)[[ name ]]
	} else{
		._jobjRef_dollar( x[["jobj"]], name )
	}
}

"$<-.Throwable" <- function( x, name, value ){
	if( name %in% names(x) ){
		x[[ name ]] <- value
	} else{
		._jobjRef_dollargets( x[["jobj"]], name, value )
	}
	x
	
}