Difference behaviour to handle exception in subscribe between subject and operator of subject
- Dominant language
- C#
- Stars
- 7.2k
- Forks
- 798
- PR merge metrics
- No merged PRs in 30d
Description
#### Bug?
> Which library version?
5.0.0
> What are the platform(s), environment(s) and related component version(s)?
dotnetfiddle and unity. I think it would be every platform
> What is the use case or problem?
- Creating a `Subject` of any type
- case 1 : Subscribe to it directly
- case 2 : use any Reactive.Linq to it (tested with `Select` and `Take`) before subscribe
- throw some exception in Subscribe
> What is the expected outcome?
It should be the same outcome. If it would stop the subscriber it should for both case. If it would be
> What is the actual outcome?
The `Subject` object will handle exception like nothing happen. While attaching any operator to it will make it vulnerable to be destroyed from exception in `Subscribe`
Is this really the expected behaviour?
> What is the stacktrace of the exception(s) if any?
> Do you have a code snippet or project that reproduces the problem?
https://dotnetfiddle.net/YxUElv
```C#
[Test]
public void Durability([NUnit.Framework.Values(true,false)]bool condition)
{
var s1 = new Subject();
var list = new List();
var d = (condition ? s1 : s1.Select(x => x).Take(1000)).Subscribe(xx => {
list.Add(xx);
Observable.Return(xx)
.Do(x => { if (x == 1) throw new Exception(); })
.Subscribe(x => list.Add(x));
});
try { s1.OnNext(5); } catch { }
try { s1.OnNext(1); } catch { }
try { s1.OnNext(10); } catch { }
Assert.That(list,Is.EqualTo(new[] { 5, 5, 1, 10, 10 }).AsCollection); // expect that Subscribe still continue invoked after exception
d.Dispose();
s1.OnNext(1000);
Assert.That(list,Has.Count.EqualTo(5));
Console.WriteLine(string.Join(",",list));
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.