Properly generate exception table for try/catch block
KT-3549 'Finally' block not run when re-throwing exception KT-3867 When catched exception occurs in finnaly block it invokes additional catch and itself #KT-3549 Fixed #KT-3867 Fixed
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
fun test1() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
throw Exception()
|
||||
} catch (x : Exception) {
|
||||
s += "Catch";
|
||||
throw x
|
||||
} finally {
|
||||
s += "Finally";
|
||||
}
|
||||
} catch (x : Exception) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
fun test2() : String {
|
||||
var s = "";
|
||||
|
||||
try {
|
||||
s += "Try";
|
||||
throw Exception()
|
||||
} catch (x : Exception) {
|
||||
s += "Catch";
|
||||
} finally {
|
||||
s += "Finally";
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun box() : String {
|
||||
if (test1() != "TryCatchFinally") return "fail1: ${test1()}"
|
||||
|
||||
if (test2() != "TryCatchFinally") return "fail2: ${test2()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
fun fail() = if (true) throw RuntimeException() else 1
|
||||
|
||||
fun test1(): String {
|
||||
var r = ""
|
||||
try {
|
||||
try {
|
||||
r += "Try"
|
||||
return r
|
||||
} catch (e: RuntimeException) {
|
||||
r += "Catch"
|
||||
return r
|
||||
}
|
||||
finally {
|
||||
r += "Finally"
|
||||
fail()
|
||||
}
|
||||
} catch (e: RuntimeException) {
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(): String {
|
||||
var r = ""
|
||||
try {
|
||||
try {
|
||||
r += "Try"
|
||||
} catch (e: RuntimeException) {
|
||||
r += "Catch"
|
||||
}
|
||||
finally {
|
||||
r += "Finally"
|
||||
fail()
|
||||
}
|
||||
} catch (e: RuntimeException) {
|
||||
return r
|
||||
}
|
||||
return r + "Fail"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (test1() != "TryFinally") return "fail1: ${test1()}"
|
||||
|
||||
if (test2() != "TryFinally") return "fail2: ${test2()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
fun unsupportedEx() = if (true) throw UnsupportedOperationException()
|
||||
fun runtimeEx() = if (true) throw RuntimeException()
|
||||
|
||||
fun test1() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
} catch (x : UnsupportedOperationException) {
|
||||
s += "Catch";
|
||||
runtimeEx()
|
||||
} catch (e: RuntimeException) {
|
||||
s += "WrongCatch"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
fun test1WithFinally() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
} catch (x : UnsupportedOperationException) {
|
||||
s += "Catch";
|
||||
runtimeEx()
|
||||
} catch (e: RuntimeException) {
|
||||
s += "WrongCatch"
|
||||
} finally {
|
||||
s += "Finally"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
fun test2() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
return s
|
||||
} catch (x : UnsupportedOperationException) {
|
||||
s += "Catch";
|
||||
runtimeEx()
|
||||
return s
|
||||
} catch (e: RuntimeException) {
|
||||
s += "WrongCatch"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
fun test2WithFinally() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
return s
|
||||
} catch (x : UnsupportedOperationException) {
|
||||
s += "Catch";
|
||||
runtimeEx()
|
||||
return s
|
||||
} catch (e: RuntimeException) {
|
||||
s += "WrongCatch"
|
||||
} finally {
|
||||
s += "Finally"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun box() : String {
|
||||
if (test1() != "TryCatch") return "fail1: ${test1()}"
|
||||
if (test1WithFinally() != "TryCatchFinally") return "fail2: ${test1WithFinally()}"
|
||||
|
||||
if (test2() != "TryCatch") return "fail3: ${test2()}"
|
||||
if (test2WithFinally() != "TryCatchFinally") return "fail4: ${test2WithFinally()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
fun unsupportedEx() = if (true) throw UnsupportedOperationException()
|
||||
fun runtimeEx() = if (true) throw RuntimeException()
|
||||
|
||||
fun test1WithFinally() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
} finally {
|
||||
s += "Finally"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
return s + "Failed"
|
||||
}
|
||||
|
||||
|
||||
fun test2WithFinally() : String {
|
||||
var s = "";
|
||||
try {
|
||||
try {
|
||||
s += "Try";
|
||||
unsupportedEx()
|
||||
return s
|
||||
} finally {
|
||||
s += "Finally"
|
||||
}
|
||||
} catch (x : RuntimeException) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if (test1WithFinally() != "TryFinally") return "fail2: ${test1WithFinally()}"
|
||||
|
||||
if (test2WithFinally() != "TryFinally") return "fail4: ${test2WithFinally()}"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user