The R Project SVN R

Rev

Rev 71192 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 71192 Rev 81297
Line 1... Line 1...
1
% File src/library/base/man/try.Rd
1
% File src/library/base/man/try.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2016 R Core Team
3
% Copyright 1995-2021 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{try}
6
\name{try}
7
\alias{try}
7
\alias{try}
8
\title{Try an Expression Allowing Error Recovery}
8
\title{Try an Expression Allowing Error Recovery}
Line 42... Line 42...
42
  instead of the default \code{\link{stderr}()},
42
  instead of the default \code{\link{stderr}()},
43
  notably when \code{try()} is used inside a \code{\link{Sweave}} code
43
  notably when \code{try()} is used inside a \code{\link{Sweave}} code
44
  chunk and the error message should appear in the resulting document.
44
  chunk and the error message should appear in the resulting document.
45
}
45
}
46
\value{
46
\value{
47
  The value of the expression if \code{expr} is evaluated without error,
47
  The value of the expression if \code{expr} is evaluated without error:
48
  but an invisible object of class \code{"try-error"} containing the
48
  otherwise an invisible object inheriting from class \code{"try-error"}
49
  error message, and the error condition as the \code{"condition"}
49
  containing the error message with the error condition as the
-
 
50
  \code{"condition"} attribute.
-
 
51
}
-
 
52
\section{Warning}{
50
  attribute, if it fails.
53
  Do not test\preformatted{
-
 
54
    if (class(res) == "try-error"))
-
 
55
}
-
 
56
  as if there is no error, the result might (now or in future) have a
-
 
57
  class of length > 1. Use \code{if(\link{inherits}(res, "try-error"))}
-
 
58
  instead.
51
}
59
}
52
\seealso{
60
\seealso{
53
  \code{\link{options}} for setting error handlers and suppressing the
61
  \code{\link{options}} for setting error handlers and suppressing the
54
  printing of error messages;
62
  printing of error messages;
55
  \code{\link{geterrmessage}} for retrieving the last error message.
63
  \code{\link{geterrmessage}} for retrieving the last error message.