码迷,mamicode.com
首页 > Web开发 > 详细

[RxJS] Observables can throw errors

时间:2016-04-10 01:11:46      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

Whenever we are writing code, we need to remember that things may go wrong. If an error happens in a function, that error will be thrown. Errors can also happen in Observables, and in this lesson we will see what is the API for throwing and catching them.

 

var bar = Rx.Observable.create(function (observer) {
  try {
    console.log(Hello);
    observer.next(42);
    observer.next(100);
    observer.next(200);
    setTimeout(function () {
      observer.next(300);
    }, 1000);
  } catch (err) {
    observer.error(err);
  }
});

bar.subscribe(function nextValueHandler(x) {
  console.log(x);
}, function errorHandler(err) {
  console.log(Something went wrong:  + err);
});

 

[RxJS] Observables can throw errors

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5373200.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!