import std/io // A panic unwinds through cleanups too. A cleanup that panics while a // `final ctl` operation unwinds replaces that unwinding (ADR 0016). effect fail { final ctl fail :: reason: String -> Never } fn attempt :: action: fn() -> a / -> Result / { handle { Ok(action ()) } with { fail reason -> Error(reason) } } pub fn main :: -> () / { defer io.println "main cleaned up" io.println "start" let r: Result = attempt fn { defer io.println "outer cleanup still runs" defer panic "cleanup failed" fail "never caught" } match r { Ok(_) -> io.println "not reached" , Error(e) -> io.println ("not reached either: " <> e) } } //> start //> outer cleanup still runs //> main cleaned up //! panic: cleanup failed