Duplicate Key Exception from Mongo DB does not gets caught

48 Views Asked by At

Trying to insert duplicate documents in mongo db with help of mongo repository.

Snippet example: try{ //insertion of duplicate doc in mongo db } catch(org.springframework.dao.DuplicateKeyException e){ // syso for something else for sake of this example }

I can see the exception getting thrown in console like errorMsg": "E11000 duplicate key error collection

But in code its not coming to catch block at all.

Why this exception cannot be caught in catch block?

Tried catching this exception with all the below exception instances: org.springframework.dao.DuplicateKeyException, com.mongodb.MongoWriteException, Exception.

Since the exception is getting thrown and its evident from the logs it should be caught in catch block.

0

There are 0 best solutions below