1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-25 21:23:55 +08:00

Catch exceptions

This commit is contained in:
Him188 2019-11-20 19:11:41 +08:00
parent 002136eefe
commit d6c9b9359f

View File

@ -72,9 +72,12 @@ suspend fun main() {
val image: Image by message
// 等同于 val image = message[Image]
reply(image + " downloading")
image.downloadTo(newTestTempFile(suffix = ".png").also { reply("Temp file: ${it.absolutePath}") })
reply(image.id.value + " downloaded")
try {
image.downloadTo(newTestTempFile(suffix = ".png").also { reply("Temp file: ${it.absolutePath}") })
reply(image.id.value + " downloaded")
} catch (e: Exception) {
reply(e.message ?: e::class.java.simpleName)
}
}
}
}