无法在 Catch 块中打印错误语句
Not able to print error statement in Catch block
我创建了一个过程,并希望在被零除时打印一条错误消息。执行即将进入 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;
但它正在打印错误消息...当我执行它时,我得到:
-----------
(0 row(s) affected)
An Error Has Occurred
我猜您可能在 SQL Server Management Studio 中执行它并将输出设置为 Grid
。
要么查看 Messages
选项卡,要么将输出设置为 Text
,使用 Results to Text
ctrl+ t
我创建了一个过程,并希望在被零除时打印一条错误消息。执行即将进入 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;
但它正在打印错误消息...当我执行它时,我得到:
-----------
(0 row(s) affected)
An Error Has Occurred
我猜您可能在 SQL Server Management Studio 中执行它并将输出设置为 Grid
。
要么查看 Messages
选项卡,要么将输出设置为 Text
,使用 Results to Text
ctrl+ t