Skip to content

Commit a44de91

Browse files
authored
Merge pull request #34478 from rwestMSFT/rw-0619-fix-419737
Refresh ERROR_SEVERITY (UUF 419737)
2 parents 8559f55 + a077546 commit a44de91

File tree

1 file changed

+86
-79
lines changed

1 file changed

+86
-79
lines changed

docs/t-sql/functions/error-severity-transact-sql.md

Lines changed: 86 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ title: "ERROR_SEVERITY (Transact-SQL)"
33
description: "ERROR_SEVERITY (Transact-SQL)"
44
author: markingmyname
55
ms.author: maghan
6-
ms.date: "03/16/2017"
6+
ms.reviewer: randolphwest
7+
ms.date: 06/19/2025
78
ms.service: sql
89
ms.subservice: t-sql
910
ms.topic: reference
@@ -18,53 +19,60 @@ helpviewer_keywords:
1819
- "ERROR_SEVERITY function"
1920
dev_langs:
2021
- "TSQL"
21-
monikerRange: ">= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || >= sql-server-linux-2017 || = azuresqldb-mi-current||=fabric"
22+
monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric"
2223
---
2324
# ERROR_SEVERITY (Transact-SQL)
25+
2426
[!INCLUDE [sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw.md)]
2527

26-
This function returns the severity value of the error where an error occurs, if that error caused the CATCH block of a TRY...CATCH construct to execute.
27-
28-
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
29-
30-
## Syntax
31-
32-
```syntaxsql
33-
ERROR_SEVERITY ( )
34-
```
35-
36-
## Return Types
37-
**int**
38-
39-
## Return Value
40-
When called in a CATCH block where an error occurs, `ERROR_SEVERITY` returns the severity value of the error that caused the `CATCH` block to run.
41-
42-
`ERROR_SEVERITY` returns NULL if called outside the scope of a CATCH block.
43-
44-
## Remarks
45-
`ERROR_SEVERITY` supports calls anywhere within the scope of a CATCH block..
46-
47-
`ERROR_SEVERITY` returns the error severity value of an error, regardless of how many times it runs or where it runs within the scope of the `CATCH` block. This contrasts with a function like @@ERROR, which only returns an error number in the statement immediately following the one that causes an error.
48-
49-
`ERROR_SEVERITY` typically operates in a nested `CATCH` block. `ERROR_SEVERITY` returns the error severity value specific to the scope of the `CATCH` block that referenced that `CATCH` block. For example, the `CATCH` block of an outer TRY...CATCH construct could have an inner `TRY...CATCH` construct. Inside that inner `CATCH` block, `ERROR_SEVERITY` returns the severity value of the error that invoked the inner `CATCH` block. If `ERROR_SEVERITY` runs in the outer `CATCH` block, it returns the error severity value of the error that invoked that outer `CATCH` block.
50-
51-
## Examples: [!INCLUDE[ssazuresynapse-md](../../includes/ssazuresynapse-md.md)] and [!INCLUDE[ssPDW](../../includes/sspdw-md.md)]
52-
53-
### A. Using ERROR_SEVERITY in a CATCH block
54-
This example shows a stored procedure that generates a divide-by-zero error. `ERROR_SEVERITY` returns the severity value of that error.
55-
56-
```sql
57-
BEGIN TRY
58-
-- Generate a divide-by-zero error.
59-
SELECT 1/0;
60-
END TRY
61-
BEGIN CATCH
62-
SELECT ERROR_SEVERITY() AS ErrorSeverity;
63-
END CATCH;
64-
GO
28+
This function returns the severity value of the error where an error occurs, if that error caused the `CATCH` block of a `TRY...CATCH` construct to execute.
29+
30+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
31+
32+
## Syntax
33+
34+
```syntaxsql
35+
ERROR_SEVERITY ( )
6536
```
66-
[!INCLUDE[ssResult](../../includes/ssresult-md.md)]
37+
38+
## Return types
39+
40+
**int**
41+
42+
## Return value
43+
44+
When called in a `CATCH` block where an error occurs, `ERROR_SEVERITY` returns the severity value of the error that caused the `CATCH` block to run.
45+
46+
`ERROR_SEVERITY` returns `NULL` if called outside the scope of a `CATCH` block.
47+
48+
## Remarks
49+
50+
`ERROR_SEVERITY` supports calls anywhere within the scope of a `CATCH` block.
51+
52+
`ERROR_SEVERITY` returns the error severity value of an error, regardless of how many times it runs or where it runs within the scope of the `CATCH` block. This contrasts with a function like [@@ERROR](error-transact-sql.md), which only returns an error number in the statement immediately following the one that causes an error.
53+
54+
`ERROR_SEVERITY` typically operates in a nested `CATCH` block. `ERROR_SEVERITY` returns the error severity value specific to the scope of the `CATCH` block that referenced that `CATCH` block. For example, the `CATCH` block of an outer `TRY...CATCH` construct could have an inner `TRY...CATCH` construct. Inside that inner `CATCH` block, `ERROR_SEVERITY` returns the severity value of the error that invoked the inner `CATCH` block. If `ERROR_SEVERITY` runs in the outer `CATCH` block, it returns the error severity value of the error that invoked that outer `CATCH` block.
55+
56+
## Examples: Azure Synapse Analytics and Analytics Platform System (PDW)
57+
58+
### A. Use ERROR_SEVERITY in a CATCH block
59+
60+
This example shows a stored procedure that generates a divide-by-zero error. `ERROR_SEVERITY` returns the severity value of that error.
61+
62+
```sql
63+
BEGIN TRY
64+
-- Generate a divide-by-zero error.
65+
SELECT 1 / 0;
66+
END TRY
67+
BEGIN CATCH
68+
SELECT ERROR_SEVERITY() AS ErrorSeverity;
69+
END CATCH
70+
GO
6771
```
72+
73+
[!INCLUDE [ssResult](../../includes/ssresult-md.md)]
74+
75+
```output
6876
-----------
6977
7078
(0 row(s) affected)
@@ -74,30 +82,31 @@ ErrorSeverity
7482
16
7583
7684
(1 row(s) affected)
77-
78-
```
79-
80-
### B. Using ERROR_SEVERITY in a CATCH block with other error-handling tools
81-
This example shows a `SELECT` statement that generates a divide by zero error. The stored procedure returns information about the error.
82-
83-
```sql
84-
BEGIN TRY
85-
-- Generate a divide-by-zero error.
86-
SELECT 1/0;
87-
END TRY
88-
BEGIN CATCH
89-
SELECT
90-
ERROR_NUMBER() AS ErrorNumber,
91-
ERROR_SEVERITY() AS ErrorSeverity,
92-
ERROR_STATE() AS ErrorState,
93-
ERROR_PROCEDURE() AS ErrorProcedure,
94-
ERROR_LINE() AS ErrorLine,
95-
ERROR_MESSAGE() AS ErrorMessage;
96-
END CATCH;
97-
GO
9885
```
99-
[!INCLUDE[ssResult](../../includes/ssresult-md.md)]
86+
87+
### B. Use ERROR_SEVERITY in a CATCH block with other error-handling tools
88+
89+
This example shows a `SELECT` statement that generates a divide by zero error. The stored procedure returns information about the error.
90+
91+
```sql
92+
BEGIN TRY
93+
-- Generate a divide-by-zero error.
94+
SELECT 1 / 0;
95+
END TRY
96+
BEGIN CATCH
97+
SELECT ERROR_NUMBER() AS ErrorNumber,
98+
ERROR_SEVERITY() AS ErrorSeverity,
99+
ERROR_STATE() AS ErrorState,
100+
ERROR_PROCEDURE() AS ErrorProcedure,
101+
ERROR_LINE() AS ErrorLine,
102+
ERROR_MESSAGE() AS ErrorMessage;
103+
END CATCH
104+
GO
100105
```
106+
107+
[!INCLUDE [ssResult](../../includes/ssresult-md.md)]
108+
109+
```output
101110
-----------
102111
103112
(0 row(s) affected)
@@ -107,20 +116,18 @@ ErrorNumber ErrorSeverity ErrorState ErrorProcedure ErrorLine ErrorMessage
107116
8134 16 1 NULL 4 Divide by zero error encountered.
108117
109118
(1 row(s) affected)
119+
```
110120

111-
```
112-
113-
## See Also
114-
[sys.messages (Transact-SQL)](../../relational-databases/system-catalog-views/messages-for-errors-catalog-views-sys-messages.md)
115-
[TRY...CATCH (Transact-SQL)](../../t-sql/language-elements/try-catch-transact-sql.md)
116-
[ERROR_LINE (Transact-SQL)](../../t-sql/functions/error-line-transact-sql.md)
117-
[ERROR_MESSAGE (Transact-SQL)](../../t-sql/functions/error-message-transact-sql.md)
118-
[ERROR_NUMBER (Transact-SQL)](../../t-sql/functions/error-number-transact-sql.md)
119-
[ERROR_PROCEDURE (Transact-SQL)](../../t-sql/functions/error-procedure-transact-sql.md)
120-
[ERROR_STATE (Transact-SQL)](../../t-sql/functions/error-state-transact-sql.md)
121-
[RAISERROR (Transact-SQL)](../../t-sql/language-elements/raiserror-transact-sql.md)
122-
[@@ERROR (Transact-SQL)](../../t-sql/functions/error-transact-sql.md)
123-
[Errors and Events Reference (Database Engine)](../../relational-databases/errors-events/errors-and-events-reference-database-engine.md)
124-
125-
121+
## Related content
126122

123+
- [sys.messages](../../relational-databases/system-catalog-views/messages-for-errors-catalog-views-sys-messages.md)
124+
- [Database Engine error severities](../../relational-databases/errors-events/database-engine-error-severities.md)
125+
- [TRY...CATCH (Transact-SQL)](../language-elements/try-catch-transact-sql.md)
126+
- [ERROR_LINE (Transact-SQL)](error-line-transact-sql.md)
127+
- [ERROR_MESSAGE (Transact-SQL)](error-message-transact-sql.md)
128+
- [ERROR_NUMBER (Transact-SQL)](error-number-transact-sql.md)
129+
- [ERROR_PROCEDURE (Transact-SQL)](error-procedure-transact-sql.md)
130+
- [ERROR_STATE (Transact-SQL)](error-state-transact-sql.md)
131+
- [RAISERROR (Transact-SQL)](../language-elements/raiserror-transact-sql.md)
132+
- [@@ERROR (Transact-SQL)](error-transact-sql.md)
133+
- [Errors and events reference (Database Engine)](../../relational-databases/errors-events/errors-and-events-reference-database-engine.md)

0 commit comments

Comments
 (0)