rt;  使用SQL的捕捉方法。

解决方案 »

  1.   

    BEGIN TRYCATCH TRY RAISERROR
    返回用户定义的错误信息并设系统标志,记录发生错误。通过使用 RAISERROR 语句,客户端可以从 sysmessages 表中检索条目,或者使用用户指定的严重度和状态信息动态地生成一条消息。这条消息在定义后就作为服务器错误信息返回给客户端。语法
    RAISERROR ( { msg_id | msg_str } { , severity , state }
        [ , argument [ ,...n ] ] )
        [ WITH option [ ,...n ] ]
      

  2.   


      if @@error <> 0
         print '出错了!'
      

  3.   

     SQL Server2005 异常处理机制(Begin try Begin Catch) 
      

  4.   

    ----try...catch用法
    begin try
       select 1/0
    end try
    begin catch 
       print'打印错误'
    end catch---raiserror的用法
    begin try
      raiserror('生成一个错误消息',11,1)
    end try
    begin catch
      select error_message() as 错误消息,
             error_severity() as严重级别,
             error_state() as state;
    end catch