I\'m trying to validate the login details of a specific user here.
This just won\'t work. I have no idea why, it never reaches the catch block even though there is a
You cannot catch MongoSecurityException as it is thrown in a background thread.
You can wait for a MongoTimeoutException to handle 'synchronously':
MongoClientOptions clientOptions = new MongoClientOptions.Builder().serverSelectionTimeout(500).build();
mongoClient = new MongoClient(serverAddress, Collections.singletonList(credential), clientOptions);
try {
String address = mongoClient.getConnectPoint();
System.out.println(address);
}catch (Throwable e){
System.out.println(e);
}
Or you can implement a ServerListener and handle asynchronously
{
MongoClientOptions clientOptions = new MongoClientOptions.Builder().addServerListener(this).build();
mongoClient = new MongoClient(host1, Collections.singletonList(credential), clientOptions);
}
@Override
public void serverDescriptionChanged(ServerDescriptionChangedEvent event) {
Throwable exception = event.getNewDescription().getException();
handle(exception);
}