October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Unhandled Errors in Angular: What Gets Caught and Where to Handle It

Angular does not catch every application error. Learn where to handle expected failures, what reaches ErrorHandler, and how browser, SSR, router, and rendering errors differ.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular sends errors it catches in framework-managed application code to the root ErrorHandler, but it does not automatically catch every error your application throws. Handle expected, recoverable failures at the callsite, where you can decide whether to retry or show a useful state; use global handling mainly to report unexpected failures. Browser, server-side rendering, routing, and rendering-boundary errors each have distinct handling paths.

Which errors does Angular catch?

Angular catches errors while invoking application code through framework-managed flows, including component construction and lifecycle methods. Those caught errors are forwarded to the root ErrorHandler. This is not a blanket catch around all application code: a service method called directly by your code is not automatically wrapped in an Angular catch.

As an Amazon Associate I earn from qualifying purchases.

The practical rule is to handle a failure where the operation is called if that code has enough context to recover. Angular’s official Unhandled errors in Angular guide says errors should be surfaced to developers at the callsite whenever possible. A global handler can report an unexpected failure, but usually cannot decide whether a particular request should be retried or what fallback makes sense to the user.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should I handle errors at the callsite?

Synchronous operations

Use try...catch around a synchronous operation when the caller can take meaningful action:

try {
  saveDraft();
} catch (error) {
  showSaveFailure();
  reportUnexpectedError(error);
}

Choose recovery based on the operation: preserve user input, offer a retry, or show a relevant failure state. Do not use a catch merely to silence an error if the application cannot continue safely.

Observable flows

For an Observable, use an operator such as RxJS catchError where the caller can select a fallback or expose an error state. This keeps recovery logic alongside the operation whose result the UI or business logic needs. Angular recommends local handling or suitable operators instead of relying on ErrorHandler for expected failures.

How do asynchronous errors reach ErrorHandler?

Angular forwards asynchronous errors when it has an explicit contract to wait for and use a result, and the failure is not already represented in returned state. For example, errors from AsyncPipe and PendingTasks.run are forwarded to ErrorHandler.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Other APIs communicate failure as state rather than forwarding it. A resource exposes its failure through its status and error properties. Read and handle those properties in the code that consumes the resource; do not assume every rejected asynchronous operation will be delivered to the global handler.

How do I handle errors globally in a browser app?

provideBrowserGlobalErrorListeners() registers listeners for browser error and unhandledrejection events and forwards them to Angular’s ErrorHandler. Angular’s guide says the CLI includes this provider by default in new applications. Check the configuration generated for your project and its Angular version before adding it; avoid duplicating equivalent custom listeners.

The provider is useful for centralized reporting of browser-global failures, not as a replacement for handling expected errors where they occur. The API details are in Angular’s provideBrowserGlobalErrorListeners reference.

What changes with server-side rendering?

For server-side rendering, Angular adds unhandledRejection and uncaughtException listeners to the server process and logs captured errors to the console. When Zone.js is in use, Angular adds only the unhandledRejection process handler because errors inside the application zone are already forwarded to ErrorHandler. Browser global listeners are therefore not the only global error mechanism to consider in an SSR application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do rendering error boundaries work?

Angular’s @boundary and @error rendering features can display fallback UI for errors during initialization or change detection, support reset, and conditionally select fallbacks. Angular marks this feature as developer preview; verify its status and availability in the Angular version used by your project before adopting it in production. See the official Error boundaries with @boundary guide.

Place the boundary where the content is declared

A boundary around ng-content does not catch errors from projected content. Put the boundary where that content is declared instead. Boundary errors may also be reported through a custom handler’s onViewError hook.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How should I handle router and resolver failures?

Route resolver failures and navigation errors have router-specific handling options. Angular documents three approaches: configure withNavigationErrorHandler, subscribe to router events, or handle the failure inside the resolver. Choose based on whether the response belongs to centralized navigation policy or to the particular data the resolver is loading. The official Route data resolvers guide describes these options.

Why do tests or startup errors behave differently?

TestBed rethrows unexpected errors

TestBed rethrows unexpected application errors by default so a test fails visibly instead of silently passing. Keep that behavior for ordinary tests; disable or alter it only when a test is specifically checking that the application remains resilient to an error.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Errors before the root instance exists

An error that occurs before Angular has created the root instance cannot yet be sent to a provided ErrorHandler. Angular notes this can happen when defining an Angular element whose tag is already present on the page. A root-level handler cannot cover failures that happen before it exists.

Where should each kind of failure be handled?

Where or how the failure occurs Preferred handling What to know
Direct synchronous call try...catch at the callsite The caller can decide whether to recover, retry, or show an error state.
Observable operation An operator such as catchError at the callsite Use it when the caller can choose recovery or a fallback.
Framework-managed application code Root ErrorHandler Angular forwards errors it catches in framework-managed flows; this does not cover every direct call.
Browser-global error or unhandledrejection provideBrowserGlobalErrorListeners(), then ErrorHandler Check whether the project’s CLI setup already includes the provider.
Resource failure Read the resource’s status and error The failure is exposed as state rather than necessarily forwarded.
Server-side rendering process failure Angular’s server process listeners and logging Behavior differs when Zone.js is in use.
Initialization or change-detection rendering failure @boundary fallback, if appropriate Developer preview; projected content must be bounded where it is declared.
Resolver or navigation failure withNavigationErrorHandler, router events, or resolver-local handling Use the router’s documented failure paths.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.