SQL Server/T-SQL Tutorial/System Settings/ERROR SEVERITY

Материал из SQL эксперт
Перейти к: навигация, поиск

ERROR_SEVERITY function

6> BEGIN TRY
7>     SELECT CONVERT(int, "ABC") AS ConvertException
8> END TRY
9> BEGIN CATCH
10>     DECLARE
11>         @ERROR_SEVERITY INT,
12>         @ERROR_STATE INT,
13>         @ERROR_NUMBER INT,
14>         @ERROR_LINE INT,
15>         @ERROR_MESSAGE VARCHAR(245)
16>
17>     SELECT
18>         @ERROR_SEVERITY = ERROR_SEVERITY(),
19>         @ERROR_STATE = ERROR_STATE(),
20>         @ERROR_NUMBER = ERROR_NUMBER(),
21>         @ERROR_LINE = ERROR_LINE(),
22>         @ERROR_MESSAGE = ERROR_MESSAGE()
23>
24>     RAISERROR("Msg %d, Line %d: %s",
25>         @ERROR_SEVERITY,
26>         @ERROR_STATE,
27>         @ERROR_NUMBER,
28>         @ERROR_LINE,
29>         @ERROR_MESSAGE)
30> END CATCH
31> GO
ConvertException
----------------
Msg 50000, Level 16, State 1, Server J\SQLEXPRESS, Line 24
Msg 245, Line 7: Conversion failed when converting the varchar value "ABC" to data type int.
(0 rows affected)
1>