Skip to content

Instantly share code, notes, and snippets.

@daveray
Created August 17, 2013 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveray/6255852 to your computer and use it in GitHub Desktop.
Save daveray/6255852 to your computer and use it in GitHub Desktop.
try in rx
rx/try
[(observable catch-clause* finally-clause?)]
Macro
A macro that takes the place of onErrorResumeNext, doFinally, and friends. The resulting
expression is an observable that acts as a pass through except for the way it handles
errors.
catch-clause => (catch ClassName name expr*)
finally-clause => (finally expr*)
When the observable calls onError, the passed exception is tested against each catch
clause. The body of the first matching clause is evaluated and the resulting Observable
is used to continue. Use rx/throw to pass the same or difference exception through on-error.
Note that each catch clause *must* evaluate to an Observable.
The body of the finally clause is an action that is executed regardless of whether the
observable completed normally or with an error.
Examples:
(rx/try
my-observable-sequence
(catch IllegalArgumentException e
(rx/return 0)) ; fallback to 0
(catch FileNotFoundException e
(rx/seq->o [5 6 7 8]) ; continue with this sequence
(catch Exception e
(rx/throw (MyWrapperException. e))) ; "throw" a new exception
(finally
(println "done")))
See:
http://netflix.github.io/RxJava/javadoc/rx/Observable.html#onErrorResumeNext(rx.util.functions.Func1)
http://netflix.github.io/RxJava/javadoc/rx/Observable.html#onErrorResumeNext%28rx.util.functions.Func1%29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment