[]previous and next page

handleError

Routes error to the nearest handler registered with catchError or onError, searching from and then its ancestors, newest handler first on each owner.

Routes error to the nearest handler registered with catchError or onError, searching from and then its ancestors, newest handler first on each owner. Handlers run untracked and restore the caller's tracking even when they rethrow. Use it for errors that happen outside any computation (a rejected promise, an event callback), so they reach the same boundary as errors thrown during rendering. A handler that throws hands its own error to the next handler up the chain. With no handler left the error is uncaught: collected until the running flush or disposal ends (which then throws it), or thrown at once otherwise.

Import#

ts
import { handleError } from "@shadow-js/core/extend";

Signature#

ts
function handleError(error: unknown, from: Owner | null): void

Parameters#

Name Description
error The thrown value.
from The owner where the error happened. Null searches no handler: the error is uncaught.

Throws#

  • The error (or the last error a handler threw) when no handler catches it and no flush or disposal is running.

Examples#

ts
import { currentOwner, handleError } from "@shadow-js/core/extend";

export function useSaveOnLoad(save: () => Promise<void>): void {
  const owner = currentOwner();
  save().catch((error: unknown) => handleError(error, owner));
}