Repository navigation
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[x] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
React recently introduced a concept called "Error Boundaries" (https://facebook.github.io/react/blog/2017/07/26/error-handling-in-react-16.html). Basically you wrap key areas of your app with .... and any component/template errors within can be handled at that level. I've run into issues with my Angular 4 app where an error in a component will cause the app to break ... sometimes the app is still navigable but often times rendering is messed up and the app just needs a restart. Most blog posts (and the Angular documentation) on error handling don't deal with rendering issues, just logging/handling any exceptions that may occur. What are strategies for gracefully handling "breaking errors" in an Angular app? Would something like make sense for Angular?
Edit: after discussing with @robwormald, it seems the current proscribed solution for handling uncaught errors would be to log them and then reload the entire app via the ErrorHandler mechanism already in Angular. This is still less than ideal (although ideally there would be no errors :-)). As applications grow, and as third party components are added/upgraded - it would be useful to introduce an the concept of an ErrorBoundary for two primary reasons:
- allows more graceful and selective degradation of the app (if a child components underneath an ErrorBoundary fail, they can be restarted)
- Error boundaries will introduce 'bulkheads' that ensure a single error won't sink the entire ship (forcing an app reload/restart), which will be more important the more likely errors are to occur (size of app, # external components, etc)
Activity
haskelcurry commentedon May 23, 2018
This would be very helpful. The fact that in Angular entire app "sinks" on a single error in some component is just embarrassing 👎
itsdevdom commentedon Oct 23, 2018
Completely agree! Having error handlers on a component level would be very helpful, allowing for more granular and flexible error management.
In our case, we have a (let's call it) "building block" in our UI library that consists of multiple components, directives and services. Our idea was to have an event on the outermost component that emits once an errors gets thrown - no matter at what place down the component hierarchy it occurred.
As a workaround, we've implemented a service to at least allow this functionality for errors we throw ourselves. Nonetheless, if Angular fails at some point, we have no ability to catch it. The application would be responsible now, and it basically must redirect to an error page / reload the application - because it cannot handle this error better (e.g. by just not rendering that part of the page).
haskelcurry commentedon Jan 22, 2019
Any updates on this?
pauldraper commentedon Jun 6, 2019
error-boundary.component.ts
error-boundary.component.html
example.component.html
sandrooco commentedon Jan 19, 2021
@pauldraper I'm trying to implement this with a child component from a library (into which I obviously can't build error handling). Do you have an idea how I could achieve this?
haskelcurry commentedon Jan 19, 2021
@sandrooco obviously, there is no way. This is not a problem that can be easily solved by some component. It's a global serious problem of Angular framework, which is being consistently ignored by the Angular Team.
shivekundefined commentedon Apr 13, 2021
There is one npm package that can help us to achieve error handling on component just like React does.
https://www.npmjs.com/package/ngx-error-boundary
This should be helpful
haskelcurry commentedon Apr 13, 2021
@shivekundefined No, that's a totally different thing. I checked the code, and this library basically just provides a service with a "handleError" method + a component to do something with an error.
@pauldraper 's answer above is much shorter and useful.
BUT, we're not talking about mere error handling here. We're talking about low-level Angular functionality: ability to ignore the errors while rendering the components, and continue to run the app gracefully. (remember that you have 3rd party components from OTHER libs, too).
That's why it says Error Boundaries: the error has power only in limited boundaries. We're not saying "Error Handling" 🙂
crutchcorn commentedon Sep 28, 2023
I believe I have an API that would solve this issue:
#51941
Would love to hear your thoughts/thumbs up/down on the matter. Even wrote a blog post (linked in issue) why it's needed
PrenexNormalForm commentedon Oct 16, 2023
This would be extremely valuable to my team as currently there is no good way to have distinct areas of the page fail gracefully without interfering with rendering the rest of the page when there is an error raised in the template.
bredziniak commentedon May 25, 2024
This would be great, it could also be achieved by new control syntax, something like:
@Try {
} @catch(e) {
<error-card [error]="e" />
}
hv0905 commentedon Dec 4, 2024
Hi, I’m looking forward to seeing this feature. My application has several components that process user-provided data, and handling errors within them is complex. I’m hoping for a way to manage errors outside of the components.
menosprezzi commentedon May 15, 2025
I was thinking how it play alongside the
@deferblock syntax since it has the@errorblock. I think it will be misunderstood. I've always been in favor that@errorshould be called@catch, even though it cant catch errors throwed by the component, but aiming to support features like this as soon as possible (and following the coherence of the other blocks like @if and @for), without generating confusion with a functionality like this, converging on a single taxonomy.If it does not converge, the markup of a deferrable view with propper error handling will be something like this 😵💫:
@defer { @try { <error-throwing /> } @catch { <handle-error [error]="$error.message"/> } } @loading { <loading /> } @error { <handle-error [error]="$error.message"/> }Or even worse:
@try { @defer { <error-throwing /> } @loading { <loading /> } @error { <handle-error [error]="$error.message"/> } } @catch { <handle-error [error]="$error.message"/> }I think that the catch block functionality should be embedded to
@defer(and deprecate the@errorin the syntax - since it was not even should exist before, btw 🙃):@defer { <error-throwing /> } @loading { <loading /> } @catch { <handle-error [error]="$error.message"/> }raven-dever commentedon Oct 23, 2025
+1 on this. I think it's a quite needed feature to ensure the stability of Angular apps
SSE-programmer commentedon Mar 18, 2026
I agree. We need a solution to this.
chriswoodie commentedon Jun 8, 2026
The new @boundary/@error syntax solves this, but will it work for images whose
srcfails to load to allow us to provide an error image instead?JeanMeche commentedon Oct 30, 2026
https://angular.dev/guide/templates/error-boundaries