## Demo: error-boundaries ### ErrorBoundaries.svelte ```svelte {#snippet caughtFallback(error: unknown)}
{error instanceof Error ? error.message : String(error)}
<svelte:boundary>
Non-hydrated components don't get an automatic boundary. If they can throw during SSR, wrap them in a hand-written <svelte:boundary> — otherwise the throw
bubbles up and crashes the whole request.
mochi:hydrate — SSR throw (recovery)
The framework auto-wraps every mochi:hydrate island in a boundary. This island throws on the server only — the boundary catches the SSR throw and the rest of the
page renders unaffected.
mochi:hydrate — client throw
SSR is fine, but the script throws synchronously once the island tries to hydrate. The defensive try/catch around hydrate() catches it and swaps the island for the
failure stub — the rest of the page (already rendered on the server) is untouched.
mochi:defer — server island throwServer islands render at a separate endpoint. When that render throws, the endpoint returns a 200 with an error stub — the browser doesn't waste retries on a deterministic failure. The user-supplied loading children stay until the response arrives.
mochi:defer — healthy island, inner mochi:hydrate client throw
The server island itself renders successfully — it's the inner mochi:hydrate
child that throws once it tries to hydrate on the client. The child's auto-boundary catches its own failure, so the rest of the server island content stays intact.
The server island itself rendered successfully.
Inside it sits a mochi:hydrate child that throws on the client — its boundary catches the failure independently: