The 3.0 Java driver takes the position that
- host names that aren't in DNS
- unreachable hosts
- incorrect authentication credentials
are severe application configuration errors that generally require human intervention and are therefore only surfaced in the API indirectly through exceptions thrown in the course of normal use of the driver.
So in both these cases the driver will eventually throw a MongoTimeoutException from any method that needs to connect to a MongoDB server. The exception will include a message indicating the root cause of the connection failure. For instance, the following program:
MongoClient mongoClient = new MongoClient(new ServerAddress("unknown-host-name"),
MongoClientOptions.builder()
.serverSelectionTimeout(5000)
.build());
mongoClient.getDatabase("admin").runCommand(new Document("ping", 1));
will throw an exception with this message:
Timed out after 30000 ms while waiting for a server that matches
ReadPreferenceServerSelector{readPreference=primary}.
Client view of cluster state is {type=UNKNOWN,
servers=[{address=unknown-host-name:27017, type=UNKNOWN, state=CONNECTING,
exception={com.mongodb.MongoSocketException: unknown-host-name},
caused by {java.net.UnknownHostException: unknown-host-name}}]