
Last chance! 50% off unlimited learning
Sale ends in
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
condition
.
Conditions created with error_cnd()
, warning_cnd()
, and
message_cnd()
inherit from "error"
, "warning"
, or "message"
.
error_cnd()
creates subclassed errors. See
"rlang_error"
.
Use cnd_signal()
to emit the relevant signal for a particular
condition class.
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
message
. See local_use_cli()
.
A trace
object created by trace_back()
.
A parent condition object.
# NOT RUN {
# 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!")
tryCatch(cnd_signal(cnd), foo = function(c) "caught!")
# }
Run the code above in your browser using DataLab