Hi,
My impression about RAISERROR(SQL 2005) was that it would cause exception in the client application.
I have a stored proc that uses RAISERROR in the catch block to pass the error from DB layer to the application layer. But the client code throws no exception.
Below is the sample code that i'm using.
Stored Proc:
Code:
CREATE PROCEDURE [dbo].[usp_ThrowException]
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
SELECT Col1, 1/0 AS 'Exception', Col2 FROM tblDemo
END TRY
BEGIN CATCH
DECLARE @Err_Msg NVARCHAR(4000), @Err_Severity INT
SELECT @Err_Msg = ERROR_MESSAGE(),
@Err_Severity = ERROR_SEVERITY()
RAISERROR(@Err_Msg, @Err_Severity, 1)
END CATCH
END
Client application code:
Code:
//........
try {
//Code to connect to DB, invoke the SP and
//retrieve the records (to be specific, using SqlDataReader to get the data)
}
catch (SqlException sqlEx) {
Console.WriteLine(string.Format("ErrorCode: {0}, Message: {1}, Number: {2}, State: {3}", sqlEx.ErrorCode, sqlEx.Message, sqlEx.Number, sqlEx.State));
}
catch (Exception oEx) {
Console.WriteLine(oEx.Message);
}
//..............
Any ideas why no exception is thrown in the client code.
Cheers,
Adarash