Examples for 'rlang::cnd'


Create a condition object

Aliases: cnd error_cnd warning_cnd message_cnd

Keywords: internal

### ** Examples

# 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.
[1] "caught!"
tryCatch(cnd_signal(cnd), foo = function(c) "caught!")
[1] "caught!"

[Package rlang version 1.1.4 Index]