Reputation: 28662
The following code works like a charm:
BEGIN TRY
BEGIN TRANSACTION
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK;
DECLARE @ErrorMessage NVARCHAR(4000),
@ErrorSeverity int;
SELECT @ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY();
RAISERROR(@ErrorMessage, @ErrorSeverity, 1);
END CATCH
But this code gives an error:
BEGIN TRY
BEGIN TRANSACTION
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK;
RAISERROR(ERROR_MESSAGE(), ERROR_SEVERITY(), 1);
END CATCH
Why?
Upvotes: 0
Views: 73
Reputation: 9784
+1 The RAISERROR statement generates an error message by either retrieving the message from the sys.messages catalog view or constructing the message string at runtime. So agreeing with the fellow @Mitch Wheat I will go with his recommendation.
Upvotes: 0
Reputation: 300837
RAISERROR()
can not take calls as its parameters. Needs to be constants or variables.
Upvotes: 3