title: How to catch exception in flutter?
body: <p>This is my exception class. Exception class has been implemented by the abstract exception class of flutter. Am I missing something?</p>
  <pre><code>class FetchDataException implements Exception {
   final _message;
   FetchDataException([this._message]);
  
  String toString() {
  if (_message == null) return &quot;Exception&quot;;
    return &quot;Exception: $_message&quot;;
   }
  }
  
  
  void loginUser(String email, String password) {
    _data
      .userLogin(email, password)
      .then((user) =&gt; _view.onLoginComplete(user))
      .catchError((onError) =&gt; {
         print('error caught');
         _view.onLoginError();
      });
  }
  
  Future &lt; User &gt; userLogin(email, password) async {
    Map body = {
      'username': email,
      'password': password
    };
    http.Response response = await http.post(apiUrl, body: body);
    final responseBody = json.decode(response.body);
    final statusCode = response.statusCode;
    if (statusCode != HTTP_200_OK || responseBody == null) {
      throw new FetchDataException(
        &quot;An error occured : [Status Code : $statusCode]&quot;);
     }
    return new User.fromMap(responseBody);
  }
  </code></pre>
  <p>CatchError doesn't catch the error when the status is not 200. In short error caught is not printed.</p>