有可能在函数内部的when块中引发异常吗?我想写这样的东西:
fun generateStatus(response: Response?, mode : Byte, deviceState : Int, timestamp: Long) : Status {
return when {
deviceState != 1 -> Status(null, timestamp, STATUS_NOT_READY, -1, null)
mode != 0 -> Status(null, timestamp, STATUS_CPU_OFF_OR_IN_BOOTLOADER, -1, null)
response == null -> Status(null, timestamp, STATUS_NO_INFORMATION, -1, null)
else -> {
...
if(response.operationID != STATUS)
throw IllegalArgumentException("Wrong status response operation id!")
}
}
}
,但是IDE(Android studio)显示错误:类型不匹配,必需的状态,找到了单位。