Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-153

Wrapping internal communication exceptions

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • 2.0
    • Affects Version/s: 1.0
    • Component/s: Feature Request
    • None
    • Minor Change

      I would like to suggest wrapping internal I/O exceptions in a custom exception (i.e. MongoCommunicationException).
      Imagine the following scenario:

      • I connect to a replica set and begin perform queries
      • Suddenly, the server I was querying goes down and the NetworkStream.Read() throws IOException, which gets to my code
      • I have no knowledge which exceptions could be thrown from the below code and if I should retry the operation (catching all types of exceptions, especially in a hosted environment is very risky, think ThreadAbortException for example).

      But, if the connection management layer of the driver would wrap all I/O-related exceptions into one type of exceptions (a new one, MongoCommunicationException or even the existing one MongoConnectionException), the driver user would instantly know that there was a problem with MongoDB connection, not some fluke in his code, and retrying/reporting failure becomes much easier.

        1. CS-153.patch
          5 kB
        2. MongoConnection.cs.patch
          0.4 kB

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            onyxmaster Aristarkh Zagorodnikov
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: