diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs index 55142268e9..44c74fc3f0 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs @@ -1356,16 +1356,9 @@ private Task ReadFromRowSourceAsync(CancellationToken cts) { _hasMoreRowToCopy = ReadFromRowSource(); // Synchronous calls for DataRows and DataTable won't block. For IDataReader, it may block. } - catch (Exception ex) + catch (Exception ex) when (_isAsyncBulkCopy && ADP.IsCatchableExceptionType(ex)) { - if (_isAsyncBulkCopy) - { - return Task.FromException(ex); - } - else - { - throw; - } + return Task.FromException(ex); } finally { @@ -2530,7 +2523,7 @@ private Task CopyColumnsAsync(int col, TaskCompletionSource source = nul source.SetResult(null); } } - catch (Exception ex) + catch (Exception ex) when (ADP.IsCatchableExceptionType(ex)) { if (source != null) { @@ -2739,7 +2732,7 @@ private Task CopyRowsAsync(int rowsSoFar, int totalRows, CancellationToken cts, source.TrySetResult(null); // This is set only on the last call of async copy. But may not be set if everything runs synchronously. } } - catch (Exception ex) + catch (Exception ex) when (ADP.IsCatchableExceptionType(ex)) { if (source != null) { @@ -2816,7 +2809,7 @@ private Task CopyBatchesAsync(BulkCopySimpleResultSet internalResults, string up } } } - catch (Exception ex) + catch (Exception ex) when (ADP.IsCatchableExceptionType(ex)) { if (source != null) { @@ -2888,7 +2881,7 @@ private Task CopyBatchesAsyncContinued(BulkCopySimpleResultSet internalResults, return CopyBatchesAsyncContinuedOnSuccess(internalResults, updateBulkCommandText, cts, source); } } - catch (Exception ex) + catch (Exception ex) when (ADP.IsCatchableExceptionType(ex)) { if (source != null) { @@ -2950,7 +2943,7 @@ private Task CopyBatchesAsyncContinuedOnSuccess(BulkCopySimpleResultSet internal return source.Task; } } - catch (Exception ex) + catch (Exception ex) when (ADP.IsCatchableExceptionType(ex)) { if (source != null) { @@ -3122,7 +3115,7 @@ private void WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet int } } } - catch (Exception ex) + catch (Exception ex) when (ADP.IsCatchableExceptionType(ex)) { _localColumnMappings = null; @@ -3299,7 +3292,7 @@ private void WriteToServerInternalRestAsync(CancellationToken cts, TaskCompletio WriteToServerInternalRestContinuedAsync(internalResults, cts, source); // internalResults is valid here. } } - catch (Exception ex) + catch (Exception ex) when (ADP.IsCatchableExceptionType(ex)) { if (source != null) { @@ -3376,7 +3369,7 @@ private Task WriteToServerInternalAsync(CancellationToken ctoken) return resultTask; } } - catch (Exception ex) + catch (Exception ex) when (ADP.IsCatchableExceptionType(ex)) { if (source != null) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Reader.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Reader.cs index bffe17baf9..33af6073fb 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Reader.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Reader.cs @@ -381,7 +381,7 @@ private void BeginExecuteReaderInternalReadStage(TaskCompletionSource co _stateObj.ReadSni(completion); } // @TODO: CER Exception Handling was removed here (see GH#3581) - catch (Exception e) + catch (Exception e) when (ADP.IsCatchableExceptionType(e)) { // Similarly, if an exception occurs put the stateObj back into the pool. // and reset async cache information to allow a second async execute diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Xml.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Xml.cs index 447627375e..39d043df12 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Xml.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.Xml.cs @@ -334,7 +334,7 @@ private void BeginExecuteXmlReaderInternalReadStage(TaskCompletionSource _stateObj.ReadSni(completion); } // @TODO: CER Exception Handling was removed here (see GH#3581) - catch (Exception e) + catch (Exception e) when (ADP.IsCatchableExceptionType(e)) { // Similarly, if an exception occurs put the stateObj back into the pool. // and reset async cache information to allow a second async execute diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDataReader.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDataReader.cs index 14c8a51b4f..bc74940c4d 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDataReader.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDataReader.cs @@ -5476,7 +5476,7 @@ private Task InvokeAsyncCall(SqlDataReaderBaseAsyncCallContext context) { task = context.Execute(null, context); } - catch (Exception ex) + catch (Exception ex) when (ADP.IsCatchableExceptionType(ex)) { task = Task.FromException(ex); }