trycatch

0th

Percentile

Evaluates an expression with the possibility to catch exceptions (DEPRECATED)

This function is deprecated. Use tryCatch() instead. Evaluates an expression with the possibility to catch exceptions. The class of the exception thrown by a standard stop() call is try-error. Since it contains a dash, the name must be specfied within quotation marks. Alternatively, the name ANY can be use to catch any exception. See examples below. Note that the order which the catch-expressions are specify is important. For instance, an ANY catch at the beginning will catch all exception even if one specify other classes afterwards.

Keywords
internal, error
Usage
trycatch(expr, ..., finally=NULL, envir=parent.frame())
Arguments
expr
The expression to be evaluated.
...
A catch list of named expressions. The expression with the same name as the class of the Exception thrown when evaluating expr
finally
An expression that is guaranteed to be called even if the expression generates an exception.
envir
The environment in which the caught expression is to be evaluated.
Details

To make trycatch() for other exception classes than try-error, the functions try() and stop() had to undergo minor(!) modification. However, they are fully compatible with the try() and stop() in the base package. To make exceptions to be thrown in the catch expression, e.g. in finally or ANY, such exceptions should extend (inherit from) the class try-error, which is for instance the case with all stop() and throw() generated exceptions. Currently, from R v1.8.0 there is a new implementation of trycatch(), which is a "wrapper" around the new tryCatch() function. If running R v1.7.1 or before the old trycatch() is used for backward compatibility.

Value

  • Returns the value of the last expression evaluated.

See Also

From R v1.8.0 the tryCatch() method is available; see conditions. For more information about exceptions see Exception. There is also throw(), stop(), try().

Aliases
  • trycatch
Examples
For a complete example see help(Exception).
Documentation reproduced from package R.oo, version 1.2.7, License: LGPL version 2.1 or newer (the releases)

Community examples

Looks like there are no examples yet.