Description Usage Arguments Details Value See Also Examples
tryLog
is implemented by calling tryCatchLog
and traps any errors that occur during the evaluation of an expression without stopping the execution
of the script (similar to try
). Errors, warnings and messages are logged.
In contrast to tryCatchLog
it returns but does not stop in case of an error and therefore does
not have the error
and finally
parameters to pass in custom handler functions.
1 2 3 4 5 6 7 8 9 10 11 12 | tryLog(
expr,
write.error.dump.file = getOption("tryCatchLog.write.error.dump.file", FALSE),
write.error.dump.folder = getOption("tryCatchLog.write.error.dump.folder", "."),
silent.warnings = getOption("tryCatchLog.silent.warnings", FALSE),
silent.messages = getOption("tryCatchLog.silent.messages", FALSE),
include.full.call.stack = getOption("tryCatchLog.include.full.call.stack", TRUE),
include.compact.call.stack = getOption("tryCatchLog.include.compact.call.stack",
TRUE),
logged.conditions = getOption("tryCatchLog.logged.conditions", NULL),
execution.context.msg = ""
)
|
expr |
R expression to be evaluated |
write.error.dump.file |
|
write.error.dump.folder |
|
silent.warnings |
|
silent.messages |
|
include.full.call.stack |
Flag of type |
include.compact.call.stack |
Flag of type |
logged.conditions |
|
execution.context.msg |
a text identifier (eg. the PID or a variable value) that will be added to msg.text
for catched conditions. This makes it easier to identify the runtime state that caused
a condition esp. in parallel execution scenarios.
The value must be of length 1 and will be coerced to character.
Expressions are not allowed.
The added output has the form: |
tryLog
is implemented using tryCatchLog
. If you need need more flexibility for
catching and handling errors use the latter.
Error messages are never printed to the stderr
connection but logged only.
The value of the expression (if expr
is evaluated without an error.
In case of an error: An invisible object of the class "try-error"
containing the error message
and error condition as the "condition"
attribute.
tryCatchLog
,
last.tryCatchLog.result
1 2 3 | tryLog(log(-1)) # logs a warning (logarithm of a negative number is not possible)
tryLog(log("a")) # logs an error
tryCatchLog(log(-1), execution.context.msg = Sys.getpid())
|
Using futile.logger for logging...
WARN [2021-07-23 02:32:53] [WARN] NaNs produced
Compact call stack:
1 tryLog(log(-1))
Full call stack:
1 tryLog(log(-1))
2 tryCatchLog(expr = expr, execution.context.msg = execution.context.msg, wri
3 tryCatch(withCallingHandlers(expr, condition = cond.handler), ..., finally
4 tryCatchList(expr, classes, parentenv, handlers)
5 tryCatchOne(expr, names, parentenv, handlers[[1]])
6 doTryCatch(return(expr), name, parentenv, handler)
7 withCallingHandlers(expr, condition = cond.handler)
8 .signalSimpleWarning("NaNs produced", base::quote(log(-1)))
9 withRestarts({
.Internal(.signalCondition(simpleWarning(msg, call),
10 withOneRestart(expr, restarts[[1]])
11 doWithOneRestart(return(expr), restart)
[1] NaN
Warning message:
In log(-1) : NaNs produced
ERROR [2021-07-23 02:32:53] [ERROR] non-numeric argument to mathematical function
Compact call stack:
1 tryLog(log("a"))
Full call stack:
1 tryLog(log("a"))
2 tryCatchLog(expr = expr, execution.context.msg = execution.context.msg, wri
3 tryCatch(withCallingHandlers(expr, condition = cond.handler), ..., finally
4 tryCatchList(expr, classes, parentenv, handlers)
5 tryCatchOne(expr, names, parentenv, handlers[[1]])
6 doTryCatch(return(expr), name, parentenv, handler)
7 withCallingHandlers(expr, condition = cond.handler)
8 .handleSimpleError(function (c)
{
log.message <- c$message
WARN [2021-07-23 02:32:53] [WARN] NaNs produced {execution.context.msg: 410850}
Compact call stack:
1 tryCatchLog(log(-1), execution.context.msg = Sys.getpid())
Full call stack:
1 tryCatchLog(log(-1), execution.context.msg = Sys.getpid())
2 tryCatch(withCallingHandlers(expr, condition = cond.handler), ..., finally
3 tryCatchList(expr, classes, parentenv, handlers)
4 withCallingHandlers(expr, condition = cond.handler)
5 .signalSimpleWarning("NaNs produced", base::quote(log(-1)))
6 withRestarts({
.Internal(.signalCondition(simpleWarning(msg, call),
7 withOneRestart(expr, restarts[[1]])
8 doWithOneRestart(return(expr), restart)
[1] NaN
Warning message:
In log(-1) : NaNs produced
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.