Right, I understand the various write concerns that one can request. What I don't quite get is the role of the method's return value vs the role the possible exception it could throw. insert both returns a WriteResult and can throw a MongoException, according to the documentation.
I'm guessing there are three possible end cases for an insertion:
- the insertion succeeds in reference to the requested write concern
- the insertion is known to have failed before the level of success specified by the write concern has been reached
- there is a timeout before a response to the getLastError request is received (if a finite timeout is requested)
Obviously, no exception is thrown in the success case. However, is there ever an error return value? Or, is an exception always thrown in the case of an error? Is there a way to programmaticallly determine the nature of the error based on what is returned or thrown so that a decision can be made as to whether or not to try a failed insertion again? Also, do you mean the behavior as to whether an exception is thrown or an error code is returned is dependent on the write concern (and not just by setting the success criteria)?