Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

catching a socket exception in flutter

Future<Response> login(String user, String pwd) async {
  final String authHeader = encodeBasicCredentials(user, pwd);
  try {
    return await get(
        'http://192.168.0.100:8080/login',
        headers: {
          HttpHeaders.AUTHORIZATION: authHeader,
        },
      );
  } catch (e) {
    if(e is SocketException){
       //treat SocketException
       print("Socket exception: ${e.toString()}");
    }
    else if(e is TimeoutException){
       //treat TimeoutException
       print("Timeout exception: ${e.toString()}");
    }
    else print("Unhandled exception: ${e.toString()}");
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #catching #socket #exception #flutter
ADD COMMENT
Topic
Name
3+8 =