Implementation:Rapidsai Cuml FIL Exceptions
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Forest_Inference |
| Last Updated | 2026-02-08 12:00 GMT |
Overview
Defines custom exception types for the Forest Inference Library (FIL) to signal model compatibility, import, and data type errors.
Description
This header provides three exception classes within the ML::fil namespace, all derived from std::exception:
unusable_model_exception: Thrown when a model is incompatible with FIL. Supports construction with no arguments (default message: "Model is not compatible with FIL"), astd::string, or aconst char*. Stores the message in astd::stringmember.
model_import_error: Thrown when model import fails. Supports construction with no arguments (default message: "Error while importing model") or aconst char*. Stores the message as a rawconst char*.
type_error: Thrown when there is a mismatch between the input data type and the model's expected type (e.g., providing doubles to a float-threshold model). Supports construction with no arguments (default message: "Model cannot be used with given data type") or aconst char*. Stores the message as a rawconst char*.
All three exceptions provide a what() method returning a human-readable error description.
Usage
Use these exceptions when working with FIL model loading and inference code. Catch unusable_model_exception to handle cases where a model format is unsupported, model_import_error for import failures, and type_error for precision mismatches between model and input data.
Code Reference
Source Location
- Repository: Rapidsai_Cuml
- File:
cpp/include/cuml/fil/exceptions.hpp
Signature
namespace ML {
namespace fil {
struct unusable_model_exception : std::exception {
unusable_model_exception();
unusable_model_exception(std::string msg);
unusable_model_exception(char const* msg);
virtual char const* what() const noexcept;
private:
std::string msg_;
};
struct model_import_error : std::exception {
model_import_error();
model_import_error(char const* msg);
virtual char const* what() const noexcept;
private:
char const* msg_;
};
struct type_error : std::exception {
type_error();
type_error(char const* msg);
virtual char const* what() const noexcept;
private:
char const* msg_;
};
} // namespace fil
} // namespace ML
Import
#include <cuml/fil/exceptions.hpp>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| msg | std::string or char const* | No | Custom error message (defaults provided for all exception types) |
Outputs
| Name | Type | Description |
|---|---|---|
| what() | char const* | Human-readable error description string |
Usage Examples
#include <cuml/fil/exceptions.hpp>
#include <iostream>
void load_and_validate_model(/* model parameters */) {
try {
// Attempt to import a tree model into FIL
// ... model loading code ...
// Check model compatibility
bool model_supported = /* check model format */;
if (!model_supported) {
throw ML::fil::unusable_model_exception(
"Model uses unsupported split type for FIL");
}
// Check data type compatibility
bool types_match = /* check float vs double */;
if (!types_match) {
throw ML::fil::type_error(
"Input data is double but model expects float thresholds");
}
} catch (const ML::fil::unusable_model_exception& e) {
std::cerr << "Model not usable: " << e.what() << std::endl;
} catch (const ML::fil::model_import_error& e) {
std::cerr << "Import failed: " << e.what() << std::endl;
} catch (const ML::fil::type_error& e) {
std::cerr << "Type mismatch: " << e.what() << std::endl;
}
}