小编idd*_*lip的帖子

从 PagingSource 的 LoadResult.Error 中提取 Throwable

我的PagingSource加载一些数据。文档建议捕获这样的异常,以便将来进行某些处理LoadResult.Error 。

 override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Item> {
            return try {
                ...
                throw SomeCatchableException()
                ...
            } catch (e: SomeCatchableException) {
                LoadResult.Error(e)
            } catch (e: AnotherCatchableException) {
                LoadResult.Error(e)
            }
        }
Run Code Online (Sandbox Code Playgroud)

但是当我尝试这样处理时:

(adapter as PagingDataAdapter).loadStateFlow.collectLatest { loadState ->

                when (loadState.refresh) {
                    is LoadState.Loading -> {
                        // *do something in UI*
                    }
                    is LoadState.Error -> {
                        // *here i wanna do something different actions, whichever exception type*
                    }
                }
            }
Run Code Online (Sandbox Code Playgroud)

我想知道哪个 Exteption 将被捕获,因为我在参数LoadResult.Error(e)中传递了它(Throwable)

我如何知道loadState处理中的异常类型?

android android-paging-3

3
推荐指数
1
解决办法
2098
查看次数

标签 统计

android ×1

android-paging-3 ×1