无法在Catch块中打印错误语句

时间:2015-03-22 20:46:49

标签: sql sql-server ssms

我创建了一个过程,并希望在除以零时打印错误消息。执行将进入catch块,但错误语句未被打印。  请帮助。

create procedure pop(@i AS INTEGER, @w AS INTEGER)

    AS
    BEGIN TRY
     SELECT @i/@w;
     END TRY
     BEGIN CATCH
     PRINT 'An Error Has Occurred'
     END CATCH




    exec pop 4,0;

1 个答案:

答案 0 :(得分:1)

但它正在打印错误消息......当我执行它时,我得到:

-----------

(0 row(s) affected)

An Error Has Occurred

我猜你可能在SQL Server Management Studio中执行它并将输出设置为Grid

使用Messages ctrl + ,查看Text标签或将输出设置为Results to Text