code: private void handleWriteException(int responseCode, Write write) {
          assert responseCode != BKException.Code.OK : "cannot handle an exception when responseCode == " + BKException.Code.OK;
          Exception ex = BKException.create(responseCode);
          try {
              if (ex instanceof BKException.BKLedgerFencedException) {
                  // We were fenced out.
                  ex = new DataLogWriterNotPrimaryException("BookKeeperLog is not primary anymore.", ex);
              } else if (ex instanceof BKException.BKNotEnoughBookiesException) {
                  // Insufficient Bookies to complete the operation. This is a retryable exception.
                  ex = new DataLogNotAvailableException("BookKeeperLog is not available.", ex);
              } else if (ex instanceof BKException.BKLedgerClosedException) {
                  // LedgerClosed can happen because we just rolled over the ledgers or because BookKeeper closed a ledger
                  // due to some error. In either case, this is a retryable exception.
                  ex = new WriteFailureException("Active Ledger is closed.", ex);
              } else if (ex instanceof BKException.BKWriteException) {
                  // Write-related failure or current Ledger closed. This is a retryable exception.
                  ex = new WriteFailureException("Unable to write to active Ledger.", ex);
              } else if (ex instanceof BKException.BKClientClosedException) {
                  // The BookKeeper client was closed externally. We cannot restart it here. We should close.
                  ex = new ObjectClosedException(this, ex);
              } else {
                  // All the other kind of exceptions go in the same bucket.
                  ex = new DurableDataLogException("General exception while accessing BookKeeper.", ex);
              }
          } finally {
              write.fail(ex, !isRetryable(ex));
          }
      }
docs: Handles an exception after a Write operation, converts it to a Pravega Exception and completes the given future
  exceptionally using it.
  
  @param responseCode   The BookKeeper response code to interpret.
  @param write          The Write that failed.