直接上代码:
GO BEGIN TRY DECLARE @res INT SET @res=1/0 PRINT 'no error' END TRY BEGIN CATCH PRINT 'Error Number :'+CAST(ERROR_NUMBER() AS VARCHAR(10)) PRINT 'Error Message :'+ERROR_MESSAGE() PRINT 'Error Severity :'+CAST(ERROR_SEVERITY() AS VARCHAR(10)) PRINT 'Error State :'+CAST(ERROR_STATE() AS VARCHAR(10)) PRINT 'Error Line :'+CAST(ERROR_LINE() AS VARCHAR(10)) PRINT 'Error Proc :'+COALESCE(ERROR_PROCEDURE(),'not within proc') END CATCH GO
错误输出信息:
Error Number :8134
Error Message :Divide by zero error encountered.
Error Severity :16
Error State :1
Error Line :3
Error Proc :not within proc