Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
Created June 9, 2023 23:06
Show Gist options
  • Select an option

  • Save monkey-codes/136d6fdc8649823e3b555fcdf7730b7f to your computer and use it in GitHub Desktop.

Select an option

Save monkey-codes/136d6fdc8649823e3b555fcdf7730b7f to your computer and use it in GitHub Desktop.
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