bracket [1] is easy to use and ensures that the cleanup operation runs, the Control.Exception module is also well documented [2]
[1]: https://hackage.haskell.org/package/base-4.20.0.1/docs/Contr...
[2]: https://hackage.haskell.org/package/base-4.20.0.1/docs/Contr...