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

前端 未结 5 1086
忘掉有多难
忘掉有多难 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:50

    SQL has an error raising mechanism

    RAISERROR ( { msg_id | msg_str | @local_variable }
    { ,severity ,state }
    [ ,argument [ ,...n ] ] )
    [ WITH option [ ,...n ] ]
    

    Just look up Raiserror in the Books Online. But.. you have to generate an error of the appropriate severity, an error at severity 0 thru 10 do not cause you to jump to the catch block.

提交回复
热议问题