haitao:
好像错误有3种:1、可以捕捉,继续执行(如:1/0);2、所属的当前的存储过程无法继续执行,但是外部调用者可以继续执行(如:select 不存在的函数过程);3、全部中止(如:1+……
[阅读: 560] 2007-10-23 09:35:45
好像错误有3种:1、可以捕捉,继续执行(如:1/0);2、所属的当前的存储过程无法继续执行,但是外部调用者可以继续执行(如:select 不存在的函数过程);3、全部中止(如:1+'a' (编译是能通过的))
create proc haitao_testp1
as
print 12/0
-- print 1+'a'
if @@error<>0
print '程序打印:发生错误1'
select '程序返回:p1-1'
select * from newid()
if @@error<>0
print '程序打印:发生错误2'
select '程序返回:p1-2'
go
--测试的存储过程2
create proc haitao_testp2
as
exec haitao_testp1
if @@error<>0
print '程序打印:调用 存储过程1 异常结束'
else
print '程序打印:调用 存储过程1 正常结束'
select '程序返回:p2'
go
--调用
exec haitao_testp2
go
--删除测试
--drop proc haitao_testp1,haitao_testp2
/*--测试结果
服务器: 消息 8134,级别 16,状态 1,过程 p1,行 8
遇到被零除错误。
发生错误1
服务器: 消息 208,级别 16,状态 1,过程 p1,行 12
对象名 'newid' 无效。
调用 存储过程1 异常结束
--*/
/*--结论2:
被调用的存储过程发生严重错误时,调用它的存储过程可以捕获错误,并可以继续执行下去
--*/
--摘自zjcxc(邹建),我测试过,无法适应语法级的错误!