Skip to content

Commit

Permalink
Merge pull request #164 from zsxwing/error
Browse files Browse the repository at this point in the history
Change "error[T]" to "error: Observable[Nothing]"
  • Loading branch information
zsxwing committed May 25, 2015
2 parents 73d950d + beacea0 commit 28d43d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1676,4 +1676,10 @@ class RxScalaDemo extends JUnitSuite {
event1ProducerSubscription.unsubscribe()
event2ProducerSubscription.unsubscribe()
}

@Test def errorExample(): Unit = {
val o1 = Observable.just(1, 2, 3)
val o2 = Observable.error(new RuntimeException("Oops"))
(o1 ++ o2).subscribe(v => println(v), e => e.printStackTrace(), () => println("completed"))
}
}
27 changes: 15 additions & 12 deletions src/main/scala/rx/lang/scala/Observable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4303,6 +4303,11 @@ trait Observable[+T]

/**
* Provides various ways to construct new Observables.
*
* @define noDefaultScheduler
* ===Scheduler:===
* This method does not operate by default on a particular [[Scheduler]].
*
*/
object Observable {
import scala.collection.JavaConverters._
Expand Down Expand Up @@ -4402,22 +4407,20 @@ object Observable {
def apply[T](f: Subscriber[T] => Unit): Observable[T] = {
toScalaObservable(rx.Observable.create(f))
}

/**
* Returns an Observable that invokes an [[rx.lang.scala.Observer]]'s [[rx.lang.scala.Observer.onError onError]]
* method when the Observer subscribes to it.
* Returns an [[Observable]] that invokes an [[Observer.onError]] method when the [[Observer]] subscribes to it.
*
* <img width="640" height="190" src="https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/error.png" alt="" />
* <img width="640" height="190" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/error.png" alt="">
*
* @param exception
* the particular error to report
* @tparam T
* the type of the items (ostensibly) emitted by the Observable
* @return an Observable that invokes the [[rx.lang.scala.Observer]]'s [[rx.lang.scala.Observer.onError onError]]
* method when the Observer subscribes to it
* $noDefaultScheduler
*
* @param exception the particular `Throwable` to pass to [[Observer.onError]]
* @return an [[Observable]] that invokes the [[Observer.onError]] method when the [[Observer]] subscribes to it
* @see <a href="http://reactivex.io/documentation/operators/empty-never-throw.html">ReactiveX operators documentation: Throw</a>
*/
def error[T](exception: Throwable): Observable[T] = {
toScalaObservable[T](rx.Observable.error(exception))
def error(exception: Throwable): Observable[Nothing] = {
toScalaObservable[Nothing](rx.Observable.error(exception))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/rx/lang/scala/ObservableTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ObservableTests extends JUnitSuite {
val msg = "msg6251"
var receivedMsg = "none"
try {
Observable.error[Int](new Exception(msg)).firstOrElse(10).toBlocking.single
Observable.error(new Exception(msg)).firstOrElse(10).toBlocking.single
} catch {
case e: Exception => receivedMsg = e.getCause().getMessage()
}
Expand Down

0 comments on commit 28d43d7

Please sign in to comment.