Define TVM_FFI_VISIT_THROW#
Defined in File visit_error_context.h
Define Documentation#
-
TVM_FFI_VISIT_THROW(ErrorKind, node)#
Throw an error from inside a visit, with
noderecorded as the innermost frame of the resulting VisitErrorContext.Use this when the bad spot is somewhere the BEGIN/END pair does not already record — typically a child field of the currently-visited node, or a helper called from a visit that has no BEGIN/END of its own. The throw site is seeded as the innermost frame; enclosing TVM_FFI_VISIT_BEGIN/END pairs continue to append their nodes on rethrow as the stack unwinds. The macro mirrors TVM_FFI_THROW — it returns an ostream you stream a message into.
If
nodehere is the same as the enclosing END’s node (a redundant throw at the same level), FindAccessPaths normalizes the consecutive duplicate during matching, so user code does not need to guard against it — but in that case the throw would have been recorded by END anyway and a plain TVM_FFI_THROW would suffice.// Visiting a TPair node; pin the bad subfield (.lhs) as the throw // site so the resulting AccessPath ends at .lhs, not at the TPair // node itself. The surrounding END appends `node` as the next frame. void Visitor::Visit(const ObjectRef& node) { TVM_FFI_VISIT_BEGIN(); if (auto pair = node.as<TPair>()) { if (!IsValid(pair.value()->lhs)) { TVM_FFI_VISIT_THROW(ValueError, pair.value()->lhs) << "invalid lhs"; } } TVM_FFI_VISIT_END(node); }
- Parameters:
ErrorKind – The kind of error to throw (e.g. TypeError, ValueError).
node – The ObjectRef at the throw site (innermost frame).