myanmarking
@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
A modern programming language that makes developers happier.