Create a condition object.

These constructors make it easy to create subclassed conditions. Conditions are objects that power the error system in R. They can also be used for passing messages to pre-established handlers. See vignette("conditions") for more information on how to use the condition system.

cnd_new(.type = NULL, ..., .msg = NULL)
cnd_error(.type = NULL, ..., .msg = NULL)
cnd_warning(.type = NULL, ..., .msg = NULL)
cnd_message(.type = NULL, ..., .msg = NULL)
The condition subclass.
Named data fields stored inside the condition object.
A default message to inform the user about the condition when it is signalled.

cnd_new() creates objects inheriting from condition. Conditions created with cnd_error(), cnd_warning() and cnd_message() inherit from error, warning or message.

See Also

cnd_signal(), with_handlers().

  • cnd_error
  • cnd_message
  • cnd_new
  • cnd_warning
# Create a condition inheriting from the s3 type "foo":
cnd <- cnd_new("foo")

# Signal the condition to potential handlers. This has no effect if no
# handler is registered to deal with conditions of type "foo":

# If a relevant handler is on the current evaluation stack, it will be
# called by cnd_signal():
with_handlers(cnd_signal(cnd), foo = exiting(function(c) "caught!"))

# Handlers can be thrown or executed inplace. See with_handlers()
# documentation for more on this.

# Note that merely signalling a condition inheriting of "error" is
# not sufficient to stop a program:

# you need to use stop() to signal a critical condition that should
# terminate the program if not handled:
# stop(cnd_error("my_error"))
Documentation reproduced from package rlang, version, License: GPL-3

Community examples

Looks like there are no examples yet.