1
2// errror handeling in sql server
3
4 CREATE PROC usp_divide(
5 @a decimal,
6 @b decimal,
7 @c decimal output
8) AS
9BEGIN
10 BEGIN TRY
11 SET @c = @a / @b;
12 END TRY
13 BEGIN CATCH
14 SELECT
15 ERROR_NUMBER() AS ErrorNumber
16 ,ERROR_SEVERITY() AS ErrorSeverity
17 ,ERROR_STATE() AS ErrorState
18 ,ERROR_PROCEDURE() AS ErrorProcedure
19 ,ERROR_LINE() AS ErrorLine
20 ,ERROR_MESSAGE() AS ErrorMessage;
21 END CATCH
22END;
23GO
24
1
2
3
4
5 CREATE PROC usp_divide(
6 @a decimal,
7 @b decimal,
8 @c decimal output
9) AS
10BEGIN
11 BEGIN TRY
12 SET @c = @a / @b;
13 END TRY
14 BEGIN CATCH
15 SELECT
16 ERROR_NUMBER() AS ErrorNumber
17 ,ERROR_SEVERITY() AS ErrorSeverity
18 ,ERROR_STATE() AS ErrorState
19 ,ERROR_PROCEDURE() AS ErrorProcedure
20 ,ERROR_LINE() AS ErrorLine
21 ,ERROR_MESSAGE() AS ErrorMessage;
22 END CATCH
23END;
24GO
25