I am currently reading the book SQL Server 2012 T-SQL Recipes and I have a query regarding Page 455 (20-5. Nested error handling).
The book contains the following code:
BEGIN TRY
PRINT Outer Try
BEGIN TRY
SELECT 1/0
END TRY
BEGIN CATCH
PRINT CONVERT (CHAR(5), ERROR_NUMBER())+Inner catch
END CATCH
END TRY
BEGIN CATCH
PRINT CONVERT(CHAR(5), ERROR_NUMBER()) + Outer Catch
END CATCH
GO
The results are
Outer Try
(0 row(s) affected)
8134 Inner Catch
The book then states that a nested try catch will work in the following order
- Outer Try block
- Outer Catch block if an error occurs
- Inner Try block
- Outer Catch if an error occurs
Is this correct? I would expect step 4 to show 4. Inner Catch if an error occurs. In the example above, the Inner catch is run after the Inner Try block returns an error.