我的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处理中的异常类型?