日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Dart中的catchError捕获顺序

發布時間:2025/7/25 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Dart中的catchError捕获顺序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先貼一下該方法的源碼:

/*** Handles errors emitted by this [Future].** This is the asynchronous equivalent of a "catch" block.** Returns a new [Future] that will be completed with either the result of* this future or the result of calling the `onError` callback.** If this future completes with a value,* the returned future completes with the same value.** If this future completes with an error,* then [test] is first called with the error value.** If `test` returns false, the exception is not handled by this `catchError`,* and the returned future completes with the same error and stack trace* as this future.** If `test` returns `true`,* [onError] is called with the error and possibly stack trace,* and the returned future is completed with the result of this call* in exactly the same way as for [then]'s `onError`.** If `test` is omitted, it defaults to a function that always returns true.* The `test` function should not throw, but if it does, it is handled as* if the `onError` function had thrown.** Note that futures don't delay reporting of errors until listeners are* added. If the first `catchError` (or `then`) call happens after this future* has completed with an error then the error is reported as unhandled error.* See the description on [Future].*/// The `Function` below stands for one of two types:// - (dynamic) -> FutureOr<T>// - (dynamic, StackTrace) -> FutureOr<T>// Given that there is a `test` function that is usually used to do an// `isCheck` we should also expect functions that take a specific argument.// Note: making `catchError` return a `Future<T>` in non-strong mode could be// a breaking change.Future<T> catchError(Function onError, {bool test(Object error)}); 復制代碼

翻譯一下主要的意思,就是這個catchError方法可以捕獲其他Futrue的異常信息,如果重寫了test方法,test返回true就可以在catchError的onError方法里捕獲到異常,如果test返回false,就把該異常繼續拋出而不會在catchError方法里被捕獲,如果不寫test默認實現一個返回true的test方法,注意catchError只能捕獲Future的異常,而不能捕獲同步代碼的異常,測試代碼如下:

import 'dart:async';Future testFutureError() {return new Future(() {throw "error";//1 // return "abc";//2}); }main() {testFutureError().then((value) {print("then " + value);}).catchError((e) {print("catchError " + e);}, test: (Object o) {print("test " + o);return true;//3 // return false;//4}).catchError((e) {print("catchError2 " + e);}, test: (_) => true); } 復制代碼

如果是上面的代碼,會輸出

test error catchError error 復制代碼

因為//3這行返回了true,所以會在第一個catchError里被捕獲。 如果//4不注釋了,把//3注釋,那么第一個catchError不能捕獲該異常,該異常會繼續拋出,然后在第二個catchError里被捕獲。具體的可自行測試。

還有就是用whenComplete方法的時候,不是所有then都執行完再執行whenComplete方法,而是then、catchError、whenComplete這些方法會按照順序(除非中途有異常會進入下一個catchError)執行,這一點和rxjava+retrofit不一樣,原生開發請知悉。

總結

以上是生活随笔為你收集整理的Dart中的catchError捕获顺序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产黄视频在线观看 | 人妻少妇久久中文字幕 | 中文成人在线 | 中文字幕av在线免费观看 | 91亚洲国产成人精品一区二区三 | 欧美黄色短视频 | 成人免费无遮挡无码黄漫视频 | 少妇厨房愉情理伦bd在线观看 | 欧美日韩免费在线观看 | 亚洲欧美变态另类丝袜第一区 | 黄色片免费在线 | 亚洲午夜精选 | 91精品国产91久久久久福利 | 国产精品久久久91 | 亚洲成人黄色影院 | 最新三级网站 | 久久久国产精品x99av | 日韩av网页| 国产欧美久久久久 | 全黄一级男人和女人 | 欧美精品二区三区四区免费看视频 | 久久免费手机视频 | 久久91视频 | 亚洲图片88| 国产a视频免费观看 | 亚洲高清色图 | 欧美大片a | a√在线观看 | 一级片一区二区三区 | 永久免费无码av网站在线观看 | 久久久精品中文字幕麻豆发布 | 欧美黑人一级爽快片淫片高清 | 不卡一区在线观看 | 美女扒开腿让男人操 | av官网在线 | 午夜中文字幕 | 欧美男人天堂网 | 绿帽单男 | 秋霞7777鲁丝伊人久久影院 | 国产做爰免费视频观看 | 亚洲中文字幕一区二区在线观看 | 亚洲青青草 | 网站免费在线观看 | 91九色视频 | 成人亚洲精品 | 97精品国产97久久久久久春色 | aa片在线观看视频在线播放 | 久久精品日韩 | 欧美www视频 | 国产精品破处 | 青草操 | 免费看黄色的视频 | 亚洲一级精品 | 亚洲视频在线看 | 边打电话边做 | 色老头在线观看 | 欧洲亚洲一区二区 | 日韩国产毛片 | 国内精品一区二区三区 | 日本作爱视频 | 精品欧美乱码久久久久久1区2区 | 精品亚洲精品 | 国产视频二区 | 成人激情免费 | 蜜臀久久99静品久久久久久 | 中国美女黄色 | 欧美视频黄色 | 日韩在线观看 | 一区二区影视 | 亚洲人人爽 | 成人作爱视频 | 麻豆美女视频 | 亚洲污污视频 | 亚洲成人麻豆 | 亚洲色图偷 | 欧美人与禽猛交乱配视频 | 成人av片免费看 | 日韩精品一区二区三区视频 | 国产精品成人在线 | 国产黄视频在线观看 | 亚洲一区二区自偷自拍 | 日批动态图 | 青青草原国产视频 | 国产黑丝一区二区 | 美美女高清毛片视频免费观看 | 老女人乱淫 | 激情九月婷婷 | 国产黄色一区二区三区 | 伊人96 | 亚洲尤物视频 | 欧美一区二区免费在线观看 | 久久久久一区二区三区 | 欧美中出| 在线免费看av | 成人毛片视频免费看 | 色黄啪啪网 | 色成人免费网站 | 男朋友是消防员第一季 | 在线观看视频国产 |