I have incorporated signals into my Angular application.
One of the signals I am using is a computed
signal, in which I deliberately introduce an exception to see how it is handled. Please note that my actual code is more intricate than this example.
public test: Signal<string> = computed(() => {
throw new Error(`Testing throwing exception`);
return 'foo';
});
<p>{{ test() }}</p>
Upon checking the console, I notice that the exception is thrown multiple times (at least 15 times) https://i.sstatic.net/IkU4Q.png
To handle unexpected exceptions, I have integrated bugsnag for error reporting. However, I observe that bugsnag reports the same exception multiple times instead of just once.
One approach that seems to work is to include a try-catch block within my computed function and manually report to bugsnag like so:
public test: Signal<string> = computed(() => {
try {
throw new Error(`Testing throwing exception`);
return 'foo';
} catch (error) {
Bugsnag.notify(error as NotifiableError);
return '';
}
});
Is there a more efficient way to handle such scenarios? It feels like handling exceptions within a "computed signal" is a common requirement.