Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 25, 2024 10:20
Show Gist options
  • Save dacr/63ed2e8ee61a61487f9a08e78f120a10 to your computer and use it in GitHub Desktop.
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/de13309c40278a56cc508a92d0c69989535a1736
// summary : ZIO learning - java unswallowed exception
// keywords : scala, zio, learning, pure-functional
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// 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