rx java - rx.exceptions.OnErrorNotImplementedException How do I avoid this error - its crashing my app -


com.myapp.test.debug e/messagequeue-jni: rx.exceptions.onerrornotimplementedexception @ rx.observable$31.onerror(observable.java:7134) @ rx.observers.safesubscriber._onerror(safesubscriber.java:154) @ rx.observers.safesubscriber.onerror(safesubscriber.java:111) @ rx.observers.safesubscriber.onnext(safesubscriber.java:137) @ rx.subjects.subjectsubscriptionmanager$subjectobserver.onnext(subjectsubscriptionmanager.java:224) @ rx.subjects.publishsubject.onnext(publishsubject.java:121) @ com.myapp.myclass.lambda$static$53(myclass.java:77) myclass.java 77 mysubject.onnext(event);

a few question ... why actual error not shown in addition error handler not implemented? secondly suppose implement function on subject? how add error handler subject. crashing app , actual error not shown. guess should implement error handler?

rxjava has observable , observer. can view observable source of stream on can perform operations such map , filter. observer kind of receiver: interface 3 methods (onnext, onerror , oncompleted) triggered observable. connect observable , observer via observable.subscribe(...) methods.

there multiple overloads of subscribe allow provide onnext, onerror , oncompleted separate functions. these functions used implement observer interface. if don't provide 3 functions (say onnext), onerror method of observer interface implemented throwing onerrornotimplementedexception.

presumably code looks this

publishsubject<integer> subject = publishsubject.create(); subject.subscribe(system.out::println); // use java 8 lambda here brevity subject.onnext(1/0); // causes error dividing 0 

you can 'catch' exception not providing onnext implementation in subscribe, providing onerror implementation:

publishsubject<integer> subject = publishsubject.create(); subject.subscribe(system.out::println, throwable::printstacktrace); subject.onnext(1/0); 

regarding last question "am supposed implement onerror function?": technically speaking no, don't need if sure observable (or subject) not produce error. in practice smart idea @ least log kind of error or recover using operator onerrorresumenext or retry. can find them in documentation.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -