Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.6/rx.all.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
//Example for the article: https://rationaldev.com/exception-handling-promises-vs-observables/
var promise = new Promise((resolve) => {
  console.log('running promise');
  console.log('about to throw exception in promise');
  throw "Error Promise";
});
promise.then( x => console.log(x));
console.log('NOTE: promise swallows exception and continues');
var source = Rx.Observable.create((observer) => {
  console.log('running observable');
  console.log('about to throw exception in observable');
  throw "Error Observable";
  observer.onNext('observable onNext');
// uncomment below to catch observable exception
// }).catch(function(e){
//   console.log('Caught observable exception and returning it');
//   return Rx.Observable.return(e);
  
});
//subscribe to observable to kick it off
source.subscribe(function(i){
  console.log(i)
});
//shows we got to the end of the program. We never get here unless we catch the observable exception
console.log('last statement running');
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x