'Crashes using Bluetooth Android studio/java

When I am using in my app and it does something it wasn't supposed to like try to connect to paired but not connected Bluetooth device. The app crashes, I want to see if there is a way to catch the errors and stop the app from crashing. I'm using

try {

    socket.connect();
} catch (IOException e) {
    Log.e("ConnectFail", "Socket.connect() Failed", e);
    //e.printStackTrace();

    break;
}

but it still crashes.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source