title: How to handle exception in mvvm android and pass that exception to our view
body: <p>I am using MVVM architecture to hit a web service through retrofit in android studio. I have handled the response of the service in my view class. But the problem i am facing is how to handle the exceptions and pass them to my view class. One way is to make constructor in my Bean class and pass both the response and error to it and update UI. But i want more optimised way to handle exceptions inside UI.</p>
  
  <p>Here is my repository code :</p>
  
  <pre><code>final MutableLiveData&lt;MyBeanClass&gt; myBeanClass = new MutableLiveData&lt;&gt;();ApiInterface apiInterface = ApiClient.getClientAuthentication().create(ApiInterface.class);
  Call&lt;MyBeanClass&gt; call = apiInterface.getData(id);
  call.enqueue(new Callback&lt;MyBeanClass&gt;() {@Override
      public void onResponse(Call&lt;MyBeanClass&gt; call, Response&lt;MyBeanClass&gt; response) {
          if(response.body()!=null) {
              myBeanClass.setValue(response.body());
          }
      }
  
      @Override
      public void onFailure(Call&lt;MyBeanClass&gt; call, Throwable t) {
       //How to handle exceptions here and pass the exception to UI without making constructor in bean class
      }
  });
  
  return myBeanClass;
  </code></pre>