MobileChromeApps / cordova-plugin-chrome-apps-sockets-udp

BSD 3-Clause "New" or "Revised" License
80 stars 39 forks source link

Unhandled exception if no internet access is active #28

Open uprtdev opened 5 years ago

uprtdev commented 5 years ago

This issue is happens in the same situation like in the similar issue in cordova-plugin-chrome-apps-sockets-tcp: https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-tcp/issues/31

On Android 7 (tested on Geotel A1) in case there is no internet connection on the device, app crashes because of the unhandled exception "java.nio.channels.UnresolvedAddressException".

For me it was solved by adding a corresponding exception handler to the void dequeueSend() method, like:

  void dequeueSend() {
...
    UdpSendPacket sendPacket = null;
    try {
...
    } catch (InterruptedException e) {
    } catch (IOException e) {
      sendPacket.callbackContext.error(buildErrorInfo(-2, e.getMessage()));
    } catch (java.nio.channels.UnresolvedAddressException e) {
      sendPacket.callbackContext.error(buildErrorInfo(-2, "Failed to resolve address"));
    }
  }