I have a Stored Procedure which sometimes return an exception after SELECT statement. For example:
BEGIN TRY
SELECT
EmployeeId,
EmployeeName
FROM dbo.abc
THROW 50000, 'exception occurs here', 16;
END TRY
BEGIN CATCH
THROW 50000, 'exception', 16;
END CATCH
I am using ExecuteReaderAsync method to read data.
In case of exception, I should get exception in application. For example:
using (var reader = await ExecuteReaderAsync())
{
while (reader.Read())
{
}
}
But I am not getting any exception.
This is a very strange behaviour. Because if this happens when we have some logic after SELECT and logic fails (e.g. any important UPDATE statement fails) then this will cause problem in the Application's behaviour.
Can somebody help me why I this strange behaviour is happening.