Is it possible to raise an error in a stored procedure manually to stop execution and jump to BEGIN CATCH block? Some analog of throw new Exception() in C#.
Here is my stored procedure's body:
BEGIN TRY
BEGIN TRAN
-- do something
IF @foobar IS NULL
-- here i want to raise an error to rollback transaction
-- do something next
COMMIT TRAN
END TRY
BEGIN CATCH
IF @@trancount > 0
ROLLBACK TRAN
END CATCH
I know one way: SELECT 1/0 But it's awful!!