I am struggling with a subscriber, which automatically unsubscribe itself on error:
observable
.subscribe(
(data) => {
// some logic encountering an error during execution
// comparable to throw new Error()
}
)
I can prevent it with using try / catch:
observable
.subscribe(
(data) => try {
// some logic encountering an error during execution
// comparable to throw new Error()
} catch(e) {
}
)
But it feels like a work around.
I have dived into the source of Subscriber and SafeSubscriber, which automatically call unsubscribe on error:
private __tryOrUnsub(fn: Function, value?: any): void {
try {
fn.call(this._context, value);
} catch (err) {
this.unsubscribe();
throw err;
}
}
Is the only way to prevent this behavior to implement an own Subscriber or using try / catch?