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
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{exitCheck}
\alias{exitCheck}
\title{Exit Error Checks}
\usage{
exitCheck()
}
\value{
Either \code{x} or the success status when called without arguments.
}
\description{
\code{exitCheck} provides a mechanism to distinguish the exit status
in \code{\link{on.exit}} expressions.
}
\details{
It generates a function that is used wihtin a function's body to
"flag" normal exits and in its \code{\link{on.exit}} expression
to check the exit status of a function.
Note that it will correctly detect errors only if all normal exit
are wrapped into a call to it.
}
\examples{
# define some function
f <- function(err){
# initialise an error checker
success <- exitCheck()
# do something on exit that depends on the error status
on.exit({
if(success()) cat("Exit with no error: do nothing\n")
else cat("Exit with error: cleaning up the mess ...\n")
})
# throw an error here
if( err ) stop('There is an error')
success(1+1)
}
# without error
f(FALSE)
# with error
try( f(TRUE) )
}
|