代码测试
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
testCrash2()
// testCrash()
}
fun testCrash(){
try {
1/0
}catch (e:Exception){
System.out.println(e)
}
}
/**
* 测试捕获 子线程崩溃
*/
fun testCrash2(){
try {
Thread {
1/0
}.start()
}catch (e:Exception){
System.out.println(e)
}
}
}
结论:
try…catch 只能捕获当前线程的异常,线程切换就捕获不到了,会发生崩溃