Introduce common ArithmeticException
Make divisionByZero test still fail in JS after introducing ArithmeticException
This commit is contained in:
+18
-8
@@ -1,15 +1,25 @@
|
|||||||
// IGNORE_BACKEND: JS_IR
|
// IGNORE_BACKEND: JS_IR
|
||||||
// IGNORE_BACKEND: JS
|
// IGNORE_BACKEND: JS
|
||||||
// reason - no ArithmeticException in JS
|
// reason - no error from division by zero in JS
|
||||||
|
|
||||||
|
fun expectFail(f: () -> Unit): Nothing? {
|
||||||
|
try {
|
||||||
|
f()
|
||||||
|
} catch (e: ArithmeticException) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
throw AssertionError("Expected ArithmeticException to be thrown")
|
||||||
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
val a1 = 0
|
val a1 = 0
|
||||||
val a2 = try { 1 / 0 } catch(e: ArithmeticException) { 0 }
|
val a2 = expectFail { 1 / 0 } ?: 0
|
||||||
val a3 = try { 1 / a1 } catch(e: ArithmeticException) { 0 }
|
val a3 = expectFail { 1 / a1 } ?: 0
|
||||||
val a4 = try { 1 / a2 } catch(e: ArithmeticException) { 0 }
|
val a4 = expectFail { 1 / a2 } ?: 0
|
||||||
val a5 = try { 2 * (1 / 0) } catch(e: ArithmeticException) { 0 }
|
val a5 = expectFail { 2 * (1 / 0) } ?: 0
|
||||||
val a6 = try { 2 * 1 / 0 } catch(e: ArithmeticException) { 0 }
|
val a6 = expectFail { 2 * 1 / 0 } ?: 0
|
||||||
|
|
||||||
try { val s1 = "${2 * (1 / 0) }" } catch(e: ArithmeticException) { }
|
val s1 = expectFail { "${2 * (1 / 0) }" } ?: "OK"
|
||||||
|
|
||||||
return "OK"
|
return s1
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,12 @@ public expect open class NoSuchElementException : RuntimeException {
|
|||||||
constructor(message: String?)
|
constructor(message: String?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SinceKotlin("1.3")
|
||||||
|
public expect open class ArithmeticException : RuntimeException {
|
||||||
|
constructor()
|
||||||
|
constructor(message: String?)
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated("This exception type is not supposed to be thrown or caught in common code and will be removed from kotlin-stdlib-common soon.")
|
@Deprecated("This exception type is not supposed to be thrown or caught in common code and will be removed from kotlin-stdlib-common soon.")
|
||||||
public expect open class NoWhenBranchMatchedException : RuntimeException {
|
public expect open class NoWhenBranchMatchedException : RuntimeException {
|
||||||
constructor()
|
constructor()
|
||||||
|
|||||||
@@ -107,6 +107,10 @@ public actual open class NoSuchElementException actual constructor(message: Stri
|
|||||||
actual constructor() : this(null)
|
actual constructor() : this(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SinceKotlin("1.3")
|
||||||
|
public actual open class ArithmeticException actual constructor(message: String?) : RuntimeException(message) {
|
||||||
|
actual constructor() : this(null)
|
||||||
|
}
|
||||||
|
|
||||||
public actual open class NoWhenBranchMatchedException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
|
public actual open class NoWhenBranchMatchedException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) {
|
||||||
actual constructor() : this(null, null)
|
actual constructor() : this(null, null)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package kotlin
|
|||||||
@SinceKotlin("1.1") public actual typealias IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException
|
@SinceKotlin("1.1") public actual typealias IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException
|
||||||
@SinceKotlin("1.1") public actual typealias UnsupportedOperationException = java.lang.UnsupportedOperationException
|
@SinceKotlin("1.1") public actual typealias UnsupportedOperationException = java.lang.UnsupportedOperationException
|
||||||
|
|
||||||
|
@SinceKotlin("1.3") public actual typealias ArithmeticException = java.lang.ArithmeticException
|
||||||
@SinceKotlin("1.1") public actual typealias NumberFormatException = java.lang.NumberFormatException
|
@SinceKotlin("1.1") public actual typealias NumberFormatException = java.lang.NumberFormatException
|
||||||
@SinceKotlin("1.1") public actual typealias NullPointerException = java.lang.NullPointerException
|
@SinceKotlin("1.1") public actual typealias NullPointerException = java.lang.NullPointerException
|
||||||
@SinceKotlin("1.1") public actual typealias ClassCastException = java.lang.ClassCastException
|
@SinceKotlin("1.1") public actual typealias ClassCastException = java.lang.ClassCastException
|
||||||
@@ -23,5 +24,4 @@ package kotlin
|
|||||||
|
|
||||||
@SinceKotlin("1.1") public actual typealias NoSuchElementException = java.util.NoSuchElementException
|
@SinceKotlin("1.1") public actual typealias NoSuchElementException = java.util.NoSuchElementException
|
||||||
|
|
||||||
|
|
||||||
@SinceKotlin("1.1") public actual typealias Comparator<T> = java.util.Comparator<T>
|
@SinceKotlin("1.1") public actual typealias Comparator<T> = java.util.Comparator<T>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class ExceptionTest {
|
|||||||
@Test fun nullPointerException() = testCreateException(::NullPointerException, ::NullPointerException)
|
@Test fun nullPointerException() = testCreateException(::NullPointerException, ::NullPointerException)
|
||||||
@Test fun classCastException() = testCreateException(::ClassCastException, ::ClassCastException)
|
@Test fun classCastException() = testCreateException(::ClassCastException, ::ClassCastException)
|
||||||
@Test fun noSuchElementException() = testCreateException(::NoSuchElementException, ::NoSuchElementException)
|
@Test fun noSuchElementException() = testCreateException(::NoSuchElementException, ::NoSuchElementException)
|
||||||
|
@Test fun arithmeticException() = testCreateException(::ArithmeticException, ::ArithmeticException)
|
||||||
|
|
||||||
@Test fun noWhenBranchMatchedException() = testCreateException(::NoWhenBranchMatchedException, ::NoWhenBranchMatchedException, ::NoWhenBranchMatchedException, ::NoWhenBranchMatchedException)
|
@Test fun noWhenBranchMatchedException() = testCreateException(::NoWhenBranchMatchedException, ::NoWhenBranchMatchedException, ::NoWhenBranchMatchedException, ::NoWhenBranchMatchedException)
|
||||||
@Test fun uninitializedPropertyAccessException() = testCreateException(::UninitializedPropertyAccessException, ::UninitializedPropertyAccessException, ::UninitializedPropertyAccessException, ::UninitializedPropertyAccessException)
|
@Test fun uninitializedPropertyAccessException() = testCreateException(::UninitializedPropertyAccessException, ::UninitializedPropertyAccessException, ::UninitializedPropertyAccessException, ::UninitializedPropertyAccessException)
|
||||||
|
|||||||
Reference in New Issue
Block a user