how to rethrow same exception in sql server
- by Shantanu Gupta
I want to rethrow same exception in sql server that has been occured in my try block.
I am able to throw same message but i want to throw same error.
BEGIN TRANSACTION
BEGIN TRY
INSERT INTO Tags.tblDomain
(DomainName, SubDomainId, DomainCode, Description)
VALUES(@DomainName, @SubDomainId, @DomainCode, @Description)
COMMIT TRANSACTION
END TRY
BEGIN CATCH
declare @severity int;
declare @state int;
select @severity=error_severity(), @state=error_state();
RAISERROR(@@Error,@ErrorSeverity,@state);
ROLLBACK TRANSACTION
END CATCH
RAISERROR(@@Error, @ErrorSeverity, @state);
This line will show error, but i want functionality something like that.
This raises error with error number 50000, but i want erron number to be thrown that i am passing @@error,
I want to capture this error no at frontend
i.e.
catch (SqlException ex)
{
if ex.number==2627
MessageBox.show("Duplicate value cannot be inserted");
}
I want this functionality. which can't be achieved using raiseerror. I dont want to give custom error message at back end.