Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in the inner observable of flatMap not rethrown #1365

Closed
dvtomas opened this issue Jun 16, 2014 · 1 comment
Closed

Exception in the inner observable of flatMap not rethrown #1365

dvtomas opened this issue Jun 16, 2014 · 1 comment

Comments

@dvtomas
Copy link

dvtomas commented Jun 16, 2014

Hi all,
I'm trying to figure out, how errors are handled in RxJava (0.19.1). Basically, I'd expect the fundamental rule to be something like: Any exception thrown within an operator is either handed to the onError handler of subscribe if one is provided, or rethrown if none is provided.

This works for the map operator:

def throwOnB2(prefix: String) = Observable.from(List(1, 2, 3))
  .map(x  prefix + x.toString)
  .map(s  if (s == "b2") throw new Exception("Bang!") else s)

throwOnB2("b").subscribe(next  println(next))

throws a rx.exceptions.OnErrorNotImplementedException: Bang! as expected.

throwOnB2("b").subscribe(
  next  println(next),
  err  println(s"error: ${err}"),
  ()  println("completed")
)

prints error: java.lang.Exception: Bang! as expected.

For nested observables joined using flatMap

def nested = Observable
  .from(List("a", "b", "c"))
  .flatMap(prefix  throwOnB2(prefix))

nested
  .subscribe(
    next  println(next),
    err  println(s"error: ${err}"),
    ()  println("completed")
  )

prints error: java.lang.Exception: Bang! as expected,

But:

nested.subscribe(next  println(next))

prints

a1
a2
a3
b1

and finishes without throwing any exception.

Is this the intended behavior? For me it is quite unfortunate, since bugs in my code can easily slip away unnoticed, but perhaps there is something I don't see.

Thank you, best regards

@headinthebox
Copy link
Contributor

@dvtomas Good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants