Raise an error manually in T-SQL to jump to BEGIN CATCH block

前端 未结 5 973
忘掉有多难
忘掉有多难 2021-02-03 19:12

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() i

5条回答
  •  难免孤独
    2021-02-03 19:29

    You could use THROW (available in SQL Server 2012+):

    THROW 50000, 'Your custom error message', 1
    THROW , , 
    

    MSDN THROW (Transact-SQL)

    Differences Between RAISERROR and THROW in Sql Server

提交回复
热议问题