Created
June 18, 2021 03:57
-
-
Save CheolhoJeon/5b5863f56c54ad2017217682d0239561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap6.ExceptionHandling | |
import atomictest.eq | |
import java.lang.Exception | |
fun toss(which: Int) = when (which) { | |
1 -> throw Exception1(1) | |
2 -> throw Exception2("Exception 2") | |
3 -> throw Exception3("Exception 3") | |
else -> "OK" | |
} | |
fun test(which: Int): Any? = | |
try { | |
toss(which) | |
} catch (e: Exception1) { | |
e.value | |
} catch (e: Exception3) { | |
e.message | |
} catch (e: Exception2) { | |
e.message | |
} | |
fun main() { | |
test(0) eq "OK" | |
test(1) eq 1 | |
test(2) eq "Exception 2" | |
test(3) eq "Exception 3" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment