0

In my project, we need to call rest API using retrofit client from several places and at each place we call retrofit client's execute method, we have to handle checked IOException, resulting a lot of try catch blocks. Is there any way I can handle this

1 Answers1

0

As you surely know in Java you have checked and unchecked exceptions:

  • unchecked: descend from RuntimeException. You're fine with them
  • checked: everything else. You'll have to catch them or the compilation will fail

The execute() method is defined to throw several checked exceptions so you will have to catch them. Alternatives?

  • Change it to an asynchronous call and provide a method that will handle the exceptions
  • Wrap the call in another method/class that already handles the exceptions
  • Try multiple catch
Alberto S.
  • 7,409
  • 6
  • 27
  • 46