Hope you have enjoyed my first part of ‘Handling error in SQL SERVER – 2012’ article.
If you have not read my first part of ‘Handling error in SQL SERVER 2012’ then please go and read first part from here. After it become very easy to understand second part onwards. This is second part of this series.
While reading first part, have these things come to your mind.
If there are statements to be executed in TRY block after the error occurred. What happened to those statements? Are those statements executed or not?
Look at sample code.
There are 4 statements in TRY Block. Statement3 and statement4 are there after the statement2 (which is raising error).
So what you think statements (3 and 4 ) will execute?
The answer is NO. Because while executing statements in the TRY Block, if an error occurs the flow of execution transfers to CATCH block.
In the above code, you can see that the after the execution of Statement2 error occured and flow of execution transfers to CATCH block. You can see clearly in message section it is printing 'Before' and 'Error!'.
In the next part, I'll explain further details regarding error handling.
Handling error in SQL SERVER 2012 Part -2
Reviewed by kamal kumar das
on
June 22, 2015
Rating:

No comments: