---
title: "Discussion on \"Error Handling in Cats Effect [Part-9]\" | Hashnode"
description: "Discussion on \"Error Handling in Cats Effect [Part-9]\". Various ways to perform error handling in Cats Effect 3"
url: "https://hashnode.com/posts/error-handling-in-cats-effect-part-9/64452d9126baa38eee9138f2"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Error Handling in Cats Effect \[Part-9\]](https://yadukrishnan.live/error-handling-in-cats-effect-part-9?utm_source=hashnode&utm_medium=feed)

Various ways to perform error handling in Cats Effect 3

Apr 23, 2023 · 3 min read · yadukrishnan.live  
Updated May 15  
Read the article

-   [#cats](https://hashnode.com/tag/cats)
-   [#functional-programming](https://hashnode.com/tag/functional-programming)

## Written by

[Yadukrishnan](https://hashnode.com/@yadukrishnan)

@yadukrishnan · Hamburg, Germany

  
[View profile](https://hashnode.com/@yadukrishnan)

Software Developer - Scala

Travel | Movies | History | Nature I am a software developer. Started my career as a Java developer, but later switched to Scala. I wish to write Scala articles which are easier for newbies to follow. I love to travel, prefer to be alone or in very small group. Love to watch movies/series.

## Responses 5

Markdown supported · ⌘↵ to post

[sammo90](https://hashnode.com/@sammo90)

[May 10](https://hashnode.com/posts/error-handling-in-cats-effect-part-9/64452d9126baa38eee9138f2/comment/6a003fc2e3eebc2e20505ac5)

// deprecated: method onError in class IO is deprecated since 3.6.0: Use onError with PartialFunction argument:

```
val loggedFailedError: IO[Int] = failedIO.onError(ex => IO.println("It failed with message: "+ex.getMessage))
```

// new:

```
  val loggedFailedError: IO[Int] =
    failedIO.onError {case ex => IO.println(s"It failed with message: ${ex.getMessage}")}
```

[Yadukrishnan](https://hashnode.com/@yadukrishnan)

[May 15](https://hashnode.com/posts/error-handling-in-cats-effect-part-9/64452d9126baa38eee9138f2/comment/6a003fc2e3eebc2e20505ac5#reply-6a072f1673afc88757763321)

Hey [sammo90](https://hashnode.com/@sammo90 "sammo90") , are you using the version 3.6.0 ? This deprecation warning has been removed from 3.6.1. I think it was due to some package visibility issue.

[sammo90](https://hashnode.com/@sammo90)

[May 15](https://hashnode.com/posts/error-handling-in-cats-effect-part-9/64452d9126baa38eee9138f2/comment/6a003fc2e3eebc2e20505ac5#reply-6a0737d673afc887577d3396)

Using Scala 3.8.3 (Windows 10): I get the warning:

```
Compiling project (Scala 3.8.3, JVM (temurin:21))
[warn] .\yadu9.sc:51:38
[warn] method onError in class IO is deprecated since 3.6.0: Use onError with PartialFunction argument
[warn]   val loggedFailedError_1: IO[Int] = failedIO.onError(ex => IO.println("It failed with message: "+ex.getMessage))
[warn]                                      ^^^^^^^^^^^^^^^^
Compiled project (Scala 3.8.3, JVM (temurin:21))
[io-compute-1] 500
[io-compute-blocker-1] -2
[io-compute-2] -2
[io-compute-blocker-1] 0
[io-compute-blocker-1] 0
[io-compute-blocker-1] -9
It failed with message: Boom!
Exception in thread "main" java.lang.RuntimeException: Boom!
...
```

Code section is:

```
  val errorIO = IO(100/0)
  val recoveredFailedIO_1: IO[Int] = errorIO.recover {
    case ex: ArithmeticException => -9
  }

  // deprecated: method onError in class IO is deprecated since 3.6.0: Use onError with PartialFunction argument
  val loggedFailedError_1: IO[Int] = failedIO.onError(ex => IO.println("It failed with message: "+ex.getMessage))

  // new:
  val loggedFailedError: IO[Int] =
    failedIO.onError {case ex => IO.println(s"It failed with message: ${ex.getMessage}")}
```

[sammo90](https://hashnode.com/@sammo90)

[May 10](https://hashnode.com/posts/error-handling-in-cats-effect-part-9/64452d9126baa38eee9138f2/comment/6a003ec9e3eebc2e204fa2b4)

We can use the method attempt to lift the value of an IO into an Either. If the IO failed, it lifts the value as Right, otherwise into a Left:

vice versa!

[Yadukrishnan](https://hashnode.com/@yadukrishnan)

[May 15](https://hashnode.com/posts/error-handling-in-cats-effect-part-9/64452d9126baa38eee9138f2/comment/6a003ec9e3eebc2e204fa2b4#reply-6a07307a73afc88757775df6)

My bad! Thanks. Corrected it.
