myanmarking
01/29/2020, 4:29 PM@Test
fun `test try-catch outside launch is useless`() = runBlockingTest {
var result: Int = 0
try {
launch {
throw IllegalStateException()
result = 1
}
} catch (e: Exception) {
result = 2
}
Assert.assertTrue(result == 0)
}
@Test
fun `test try-catch inside launch catch the exception`() = runBlockingTest {
var result: Int = 0
launch {
try {
throw IllegalStateException()
result = 1
} catch (e: Exception) {
result = 2
}
}
Assert.assertTrue(result == 2)
}
Abhishek Bansal
01/29/2020, 4:36 PM