How to catch exception when creating MongoClient instance

后端 未结 4 2050
不知归路
不知归路 2020-12-21 07:35

I am using Mongo DB java driver to connect to mongo instance. Below is the code I am using to create the MongoClient instance.

try {
            new MongoCl         


        
4条回答
  •  一个人的身影
    2020-12-21 08:37

      new MongoClient("localhost", 1111);
    
            } catch (MongoSocketOpenException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    

    You just have to name the appropriate exception in the catch block. This applies to any exception. You can add as many catch blocks for each unique exception

提交回复
热议问题