Kotlin:是否有可能在when块中作为最后一条语句引发异常?

时间:2019-12-19 16:42:38

标签: android android-studio kotlin

有可能在函数内部的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)显示错误:类型不匹配,必需的状态,找到了单位。

0 个答案:

没有答案