为什么选择“订阅”不需要异常处理程序重新抛出异常? [英] Why does "Subscribe" that doesn't take an exception handler rethrow the exception?

查看:161
本文介绍了为什么选择“订阅”不需要异常处理程序重新抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不喜欢这种行为,我认为这对创建功能强大的应用程序是一种不利。

I don't like this behavior, I think it is a detriment to creating functioning and robust applications.

它基本上迫使你总是提供一个空的异常处理函数对于您在发生异常时不想做任何事情的实例的所有订阅功能。

It basically forces you to always provide an empty exception handling function to all your Subscribe functions for instances in which you don't want to do anything in the event of an exception.

请考虑更改此项。  它会导致整个地方出现丑陋的代码。  我想订阅一个成功的异步结果 - 如果失败则失败,不要让我的整个应用程序爆炸!

Please consider changing this.  It leads to ugly code all over the place.  I want to subscribe to a successful asynchronous result - if it fails it fails, don't make my whole application blow up!

另外,我坚信Action提供的onNext应该包装在try / catch中,如果它导致异常,它应该由提供的onError函数处理。  如果没有提供onError函数,只需吃掉错误:P

Also, I strongly believe that the Action provided for onNext should be wrapped in a try/catch, and if it causes an exception, it should be handled by the provided onError function.  And if no onError function was provided, just eat the error :P

至少,将它设为我们可以打开或关闭的切换,类似于Observable.ReThrowsSubscribeExceptions = false ;

At the very least, make this a toggle we can have on or off, something like Observable.ReThrowsSubscribeExceptions = false;

谢谢。

推荐答案

我读过这个帖子:  < a href ="http://social.msdn.microsoft.com/Forums/en-US/rx/thread/ee5dba5d-eea9-4d85-8f58-c2e1c71ef33a"rel ="nofollow"> http://social.msdn。 microsoft.com/Forums/en-US/rx/thread/ee5dba5d-eea9-4d85-8f58-c2e1c71ef33a

并且没有看到一个好的论据至少有一个全局切换开关,更不用说将其作为默认行为!

and don't see a single good argument for not at least having a global toggle switch for this, let alone making it the default behavior!


这篇关于为什么选择“订阅”不需要异常处理程序重新抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆