-
Type: Improvement
-
Resolution: Done
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: Error Handling
-
None
Due to Kotlin not supporting checked exceptions, it is possible to break expectations we have in Java, and throw a checked exception from a method that does not declare throwing checked exceptions. See the discussion in https://github.com/mongodb/mongo-java-driver/pull/881 for more details. In order to work around this problem, we should do the following:
- Treat any method as being able to throw checked exception even it is not declared (despite this not being true for all methods, for simplicity and robustness it is better to treat all of them this way).
- Replace all catch blocks that catch RuntimeException s (or subclasses, but those are harder to find) with blocks that catch Exception.
- Explicitly look at the known places were the driver may execute user-provided code and add code that wraps checked exceptions in unchecked ones. jeff.yemin@mongodb.com came up with the following list
- withTransaction
- authenticator-related callbacks
- any event listener
- Bson.toBsonDocument (in case someone has gone to the trouble to implement the Bson interface)