为什么在Kotlin中(除了在try-with-resources中,在Java中也是如此)仅写try {}块是不可能的?例如:
允许该功能
fun tryFunction(){
try{print("hello world!")}finally {}
}
Run Code Online (Sandbox Code Playgroud)
虽然这是不允许的
fun tryFunction(){
try{print("hello world!")} //build error "Expecting 'catch' or 'finally'"
}
Run Code Online (Sandbox Code Playgroud)
尽管第一个示例中的finally {}块没有任何作用