Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:18
Show Gist options
  • Select an option

  • Save dacr/63ed2e8ee61a61487f9a08e78f120a10 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/63ed2e8ee61a61487f9a08e78f120a10 to your computer and use it in GitHub Desktop.
ZIO learning - java unswallowed exception / published by https://github.com/dacr/code-examples-manager #d73bf41f-e5d5-42d1-97d9-8c55662f3c65/58abcec270f88d98b8af6a4c59f79134bc1e44c2
// summary : ZIO learning - java unswallowed exception
// keywords : scala, zio, learning, pure-functional
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : d73bf41f-e5d5-42d1-97d9-8c55662f3c65
// created-on : 2021-10-30T19:45:50+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.4.2"
//> using dep "dev.zio::zio:2.0.13"
//> using dep "fr.janalyse::zio-worksheet:2.0.13.0"
// ---------------------
/*
inspired from
- [John A De Goes - ZIO: Next-Generation Effects in Scala](https://www.youtube.com/watch?v=mkSHhsJXjdc)
- +23:30
*/
import zio.*, zio.worksheet.*
try {
try throw new Error("e1")
finally throw new Error("e2")
} catch {
case e: Error => println(s"java try/finally reports $e")
}
println("Error 'e1' in traditional java is lost in a black hole !")
val logic1 =
ZIO
.fail("e1")
.ensuring(ZIO.fail(throw new Error("e2")))
.catchAll(e => ZIO.logError(s"ZIO reports $e"))
println("while ZIO reports error 'e1' !")
// -------------------------------------------------------------
logic1.unsafeRun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment