7.1 Conditions

In the defaults, mlr3 does not handle catch conditions. Thus, the exception raised by the debug learner stops the execution and can be tracebacked:

task = mlr_tasks$get("spam")
learner = mlr_learners$get("classif.debug")
learner$param_set$values = list(error_train = TRUE)
e = Experiment$new(task, learner)
e$train()
## INFO [mlr3] Training learner 'classif.debug' on task 'spam' ...
## Error: Error in learner$train(task): Error from classif.debug->train()

Note that mlr3 adds the class “trainError” to the error condition. This allows us to differentiate errors thrown by the learner from other errors via tryCatch():

tryCatch(e$train(),
  trainError = function(e) { message("model failed to fit") }
)
## INFO [mlr3] Training learner 'classif.debug' on task 'spam' ...
## model failed to fit

Analogously to “trainError”, an exception with class “predictError” is raised if the learner is unable to predict, and a “scoreError” is raised if the performance measure fails.