[]previous and next page

onError

Registers an error handler on the current owner.

Registers an error handler on the current owner. It receives errors thrown in this owner's scope (its effects, memos, cleanups and child owners) that no closer handler took. Handlers on the same owner are tried newest first; a handler that throws passes its own error to the next handler up. Outside any owner the call does nothing; development builds warn NO_OWNER_ERROR.

Import#

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

Signature#

ts
function onError(handler: ErrorHandler): void

Parameters#

Name Description
handler Receives the error, untracked. Throw from it to pass an error on to the next handler.

Examples#

ts
import { onError, useEffect } from "@shadow-js/core";

function Dashboard() {
  onError((error) => console.error("dashboard failed:", error));
  useEffect(() => {
    throw new Error("widget crashed"); // reaches the handler above
  });
  return null;
}