Create a condition objectSource:
These constructors create subclassed conditions, the objects that power the error, warning, and message system in R.
cnd()creates bare conditions that only inherit from
Conditions created with
error_cnd()creates subclassed errors. See
cnd_signal() to emit the relevant signal for a particular
cnd(class, ..., message = "", call = NULL, use_cli_format = NULL) error_cnd( class = NULL, ..., message = "", call = NULL, trace = NULL, parent = NULL, use_cli_format = NULL ) warning_cnd( class = NULL, ..., message = "", call = NULL, use_cli_format = NULL ) message_cnd( class = NULL, ..., message = "", call = NULL, use_cli_format = NULL )
The condition subclass.
<dynamic> Named data fields stored inside the condition object.
A default message to inform the user about the condition when it is signalled.
A function call to be included in the error message. If an execution environment of a running function, the corresponding function call is retrieved.
Whether to use the cli package to format
traceobject created by
A parent condition object.
# Create a condition inheriting only from the S3 class "foo": cnd <- cnd("foo") # Signal the condition to potential handlers. Since this is a bare # condition the signal has no effect if no handlers are set up: cnd_signal(cnd) # When a relevant handler is set up, the signal transfers control # to the handler with_handlers(cnd_signal(cnd), foo = function(c) "caught!") #> Warning: `with_handlers()` is deprecated as of rlang 1.0.0. #> ℹ Please use `tryCatch()`, `withCallingHandlers()`, or `try_fetch()`. #> This warning is displayed once every 8 hours. #>  "caught!" tryCatch(cnd_signal(cnd), foo = function(c) "caught!") #>  "caught!"