Callbacks¶
safe() wraps a CatBoost callback so user exceptions surface after fit() instead of being silently swallowed by the C++ training loop.
from catboost_utils.callbacks import safe
def my_callback(info):
if info.iteration > 100:
raise RuntimeError("debug")
cb = safe(my_callback)
model.fit(X, y, callbacks=[cb])
cb.raise_if_failed() # raises CBXError with original traceback as __cause__
Both function callbacks (called as cb(info)) and class-based callbacks (cb.after_iteration(info)) are supported. On the first exception the wrapper returns False so CatBoost stops training cleanly; the captured exception list is available as cb.exceptions.
catboost_utils.callbacks.safe.safe ¶
Wrap callback so exceptions surface after fit() instead of being lost.
Usage::
cb = safe(my_callback)
model.fit(X, y, callbacks=[cb])
cb.raise_if_failed()