Skip to main content

How does effect handle errors?

If an error occurs inside effect(), Angular catches it so the application does not "crash". The error is simply printed to the console, but it does not break the work of other signals and effects.

Example:

ts
import { signal, effect } from '@angular/core'; const value = signal(0); effect(() => { if (value() > 3) { throw new Error('Value is too large!'); } console.log('Value:', value()); });

When value becomes greater than 3, Angular will print the error to the console, but the rest of the application will keep working.

The main point:

  • errors do not stop the reactive system;
  • you can wrap the code in try...catch yourself if you want to handle them your own way:
ts
effect(() => { try { riskyOperation(); } catch (e) { console.error('Error in effect:', e); } });

This way you control what happens on failure yourself.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.