tomcat启动设备未就绪_安全启动异常就绪协程

tomcat启动设备未就绪

Launching suspend functions in Kotlin can be a complicated affair. Managing your CoroutineScope and making sure exceptions are handled properly can be confusing and easy to forget.

在Kotlin中启动suspend功能可能很复杂。 管理您的CoroutineScope并确保正确处理了异常会造成混乱,并且容易忘记。

In Android, when using the ViewModel or Lifecycle specific scopes this gets much easier. We let the Android system provide a CoroutineScope and manage killing our coroutines when the lifecycle of those things end.

在Android中,使用ViewModelLifecycle特定范围时,这变得容易得多。 我们让Android系统提供一个CoroutineScope并在这些生命周期结束时管理杀死我们的协程。

fun getObjectFromNetwork() {
       
viewModelScope.launch {
val response = networkRepository.getObject()
}
}

However, there are cases when exceptions can be thrown from the CoroutineScope. A real life example I experienced recently was a SocketTimeoutException that was thrown from a Retrofit call I was making using a suspend function. The result is an Android app crash, which is definitely not desired when network calls can result in many different thrown exceptions.

但是,在某些情况下,可以从CoroutineScope抛出异常。 我最近遇到的一个现实生活中的例子是SocketTimeoutException ,它是我通过使用suspend函数进行的Retrofit调用引发的。 结果是Android应用程序崩溃 ,当网络调用会导致许多不同的引发异常时,绝对不希望

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值