File: Exceptions.Rd

package info (click to toggle)
rjava 1.0-11-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,184 kB
  • sloc: java: 13,223; ansic: 5,479; sh: 3,776; xml: 325; makefile: 250; perl: 33
file content (55 lines) | stat: -rw-r--r-- 1,556 bytes parent folder | download | duplicates (8)
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
49
50
51
52
53
54
55
\name{Exceptions}
\alias{Exceptions}
\alias{$.Throwable}
\alias{$<-.Throwable}
\title{Exception handling}
\description{R handling of java exception}
\usage{
	\S3method{$}{Throwable}(x, name )
	\S3method{$}{Throwable}(x, name ) <- value
}
\arguments{
	\item{x}{condition}
	\item{name}{...}
	\item{value}{...}
}
\details{
	Java exceptions are mapped to R conditions that are relayed by the
	\code{\link{stop}} function. 
	
	The R condition contains the actual exception object as the 
	\code{jobj} item.
	
	The class name of the R condition is made of a vector 
	of simple java class names, the class names without their package
	path. This allows the R code to use direct handlers similar to 
	direct exception handlers in java. See the example below. 
}
\examples{
\dontshow{.jinit()}

Integer <- J("java.lang.Integer")
tryCatch( Integer$parseInt( "10.." ), NumberFormatException = function(e){
	e$jobj$printStackTrace() 
} )

# the dollar method is also implemented for Throwable conditions, 
# so that syntactic sugar can be used on condition objects
# however, in the example below e is __not__ a jobjRef object reference
tryCatch( Integer$parseInt( "10.." ), NumberFormatException = function(e){
	e$printStackTrace() 
} )


\dontshow{
tryCatch( Integer$parseInt( "10.." ), NumberFormatException = function(e){
	classes <- class( e )
	stopifnot( "NumberFormatException" \%in\% classes )
	stopifnot( "Exception" \%in\% classes )
	stopifnot( "Object" \%in\% classes )
	stopifnot( "error" \%in\% classes )
	stopifnot( "condition" \%in\% classes )
} )
}

}