use dorben
go
begin try
-- generate a divide-by-zero error.
select 1/0;
end try
begin catch
select
error_number() as errornumber,
error_severity() as errorseverity,
error_state() as errorstate,
error_procedure() as errorprocedure,
error_line() as errorline,
error_message() as errormessage;
end catchcreate table test
(tid int identity primary key,
tname varchar(20)
)--將 select 1 插入test 不複核表的資料型別,造成異常
declare @returnvalue int
select @returnvalue = 2
begin transaction
begin try
insert into test
select 1
union all
select 'b'
union all
select 'c'
select @returnvalue = 1
commit transaction
end try
begin catch
rollback transaction
print '發生異常'
select error_message() as errormessage
select @returnvalue = 0
end catch
select @returnvalue
go
通用返回格式
業務操作結果資訊類,對操作結果進行封裝 public class operationresult 初始化乙個 定義返回訊息的業務操作結果資訊類 的新例項 業務操作結果型別 業務返回訊息 public operationresult operationresulttype resulttype,str...
try catch裡面try catch巢狀
try catch裡能否內嵌try catch?答案是肯定的。但是等內層try catch出異常之後是個什麼執行順序呢?看下面 static void main string args catch exception ex finally console.readkey private static...
捕捉異常try catch
1,當 在執行時可能出現異常時用try catch 捕捉異常,這樣程式出現異常不會立即跳出程式,可以經過處理後讓程式繼續執行或者跳出。例如 string a 12211a try catch exception e 2,還有很多其他異常,列舉一些常見異常 算術異常類 arithmeticexecpt...