Table of Contents

Method UseFallback

Namespace
Velvet
Assembly
Velvet.Docs.dll

UseFallback(Func<Exception, VNode>)

Registers a fallback factory inside Render() of an [Component(IsErrorBoundary = true)] component. When this component catches a Render exception from a child, the registered factory is invoked to produce the fallback VNode. This API expresses, in functional Velvet, the Error Boundary pattern of returning a fallback when a descendant render throws. Must be called during Render since it is overwritten on every render.

public static void UseFallback(Func<Exception, VNode> factory)

Parameters

factory Func<Exception, VNode>

Factory that receives the caught exception and returns the fallback VNode. Must not be null.

Remarks

When called from a non-EB component ([Component] with IsErrorBoundary=false), the factory is still stored on the fiber, but RenderFallback is only reached on the Error Boundary path, so it is effectively a no-op. Do not call this hook from non-EB components.

Bubble-up: when the factory returns null or itself throws, the exception bubbles to the next enclosing Error Boundary, ultimately reaching the root as an unhandled exception when no boundary catches it.

UseFallback(Func<Exception, ErrorInfo, VNode>)

Two-argument fallback factory variant that receives the caught exception and an ErrorInfo with the throwing fiber's ComponentStack, describing where the error was caught.

public static void UseFallback(Func<Exception, ErrorInfo, VNode> factory)

Parameters

factory Func<Exception, ErrorInfo, VNode>

Factory that receives (exception, info) and returns the fallback VNode. Must not be null.

Remarks

Same bubble-up semantics as the single-arg overload: returning null or throwing re-propagates the original exception to the next enclosing Error Boundary.