Created
June 9, 2023 23:06
-
-
Save monkey-codes/136d6fdc8649823e3b555fcdf7730b7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| fun fn(i: Int): Int { | |
| val x: Int = throw Exception("boom") | |
| return try { | |
| i + x | |
| } catch(e: Exception){ | |
| 42 | |
| } | |
| } | |
| val i = fn(1) // Exception("boom") | |
| // Now substitute x with its expression | |
| fun fn(i: Int): Int { | |
| return try { | |
| i + (throw Exception("boom")) as Int | |
| } catch(e: Exception){ | |
| 42 | |
| } | |
| } | |
| val i = fn(1) // 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment