Constructs and throws typed exceptions, annotating each message with the owning op name and the current ErrorContext trace.
Every throw helper formats its message as
"<op>: <msg> [trace=<chain>]" (the [trace=...] suffix is omitted
when the context stack is empty) and then dispatches to the appropriate
LucidError subclass. Helpers are marked [[noreturn]] so
callers can use them as drop-in replacements for throw without
confusing the compiler's control-flow analysis.
ErrorBuilder is stateless beyond the owning op name — it never
holds a reference to a tensor and is safe to construct on the stack at
the throw site.
See Also
ErrorContext : Owns the thread-local trace that ErrorBuilder
consumes.
Validator : Layered on top of ErrorBuilder for tensor
precondition checks.
Parameters
op_namestd::string, std::string_view, or const char*Examples
`
ErrorBuilder("my_op").shape_mismatch(expected, got, "weight tensor");
ErrorBuilder("conv2d").not_implemented("dilation>1 on integer dtypes");
`Constructors
1ErrorBuilder
void ErrorBuilder(int op_name)Constructs a builder owning the given op name.
Parameters
op_namestd::stringop_. Used as the prefix of every formatted message produced by this builder.Methods
7device_mismatch
void device_mismatch(Device expected, Device got, const int & detail)Throws a DeviceMismatch, converting Device enumerators to their canonical string names before construction.
Parameters
expectedDevicegotDevicedetailconst std::string&= None"".Raises
DeviceMismatchThrows a DtypeMismatch, converting Dtype enumerators to their canonical string names before construction.
Parameters
expectedDtypegotDtypedetailconst std::string&= None"".Raises
DtypeMismatchThrows a generic LucidError with the message prepended by the op name and the current trace.
Parameters
msgconst std::string&Raises
LucidErrorReturns "<op_>: <msg> [trace=<chain>]" (the [trace=...] suffix is omitted when the current ErrorContext trace is empty). Used by the throw helpers that take a free-form message.
Throws an IndexError with the op name and trace.
Parameters
msgconst std::string&Raises
IndexErrorThrows a NotImplementedError with the op name and trace.
Use for combinations the engine recognises but does not yet support (e.g. an unsupported dtype on a specific backend).
Parameters
msgconst std::string&Raises
NotImplementedErrorshape_mismatch
void shape_mismatch(const int & expected, const int & got, const int & detail)Throws a ShapeMismatch with the op name, optional detail, and current trace combined as the exception's context field.
Parameters
expectedconst Shape&gotconst Shape&detailconst std::string&= None"rhs") appended after the op name when non-empty. Defaults to "".Raises
ShapeMismatch