Skip to content

Instantly share code, notes, and snippets.

@gabrieljones
Created October 17, 2023 15:50
Show Gist options
  • Save gabrieljones/3d4ad71cbe678349586c07b086e666ff to your computer and use it in GitHub Desktop.
Save gabrieljones/3d4ad71cbe678349586c07b086e666ff to your computer and use it in GitHub Desktop.
package com.gabrieljones
import scala.collection.mutable.ListBuffer
object NestedFinally {
def main(args: Array[String]): Unit = {
val es: ListBuffer[Exception] = ListBuffer.empty
try {
try {
throw new Exception("1")
} finally {
print("A")
try {
throw new Exception("2")
} catch {
case e: Exception =>
es += e
print("B")
} finally {
print("C")
}
}
} catch {
case e: Exception =>
es += e
print("D")
}
println()
es.foreach(println)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment