Catch missing exceptions thrown under Bot CoroutineScope

This commit is contained in:
Him188 2020-02-14 20:19:38 +08:00
parent 5b4e99c52d
commit 7451991973

View File

@ -38,7 +38,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
private val botJob = SupervisorJob(configuration.parentCoroutineContext[Job])
override val coroutineContext: CoroutineContext =
configuration.parentCoroutineContext + botJob + (configuration.parentCoroutineContext[CoroutineExceptionHandler]
?: CoroutineExceptionHandler { _, e -> e.logStacktrace("An exception was thrown under a coroutine of Bot") })
?: CoroutineExceptionHandler { _, e -> logger.error("An exception was thrown under a coroutine of Bot", e) })
@Suppress("CanBePrimaryConstructorProperty") // for logger
final override val account: BotAccount = account