70-465 · Question #69
70-465 Question #69: Real Exam Question with Answer & Explanation
The correct answer is B: Use a TRY CATCH block in the called stored procedures.. When handling errors in nested stored procedures with minimal custom code, TRY...CATCH blocks provide structured, centralized error handling without requiring repetitive @@ERROR checks after every statement.
Question
You need to recommend a solution for the error handling of USP_3. The solution must minimize the amount of custom code required. What should you recommend?
Options
- AUse the @@ERROR variable in the nested stored procedures.
- BUse a TRY CATCH block in the called stored procedures.
- CUse the @@ERROR variable in the called stored procedures.
- DUse the RAISERROR command in the nested stored procedures.
Explanation
When handling errors in nested stored procedures with minimal custom code, TRY...CATCH blocks provide structured, centralized error handling without requiring repetitive @@ERROR checks after every statement.
Common mistakes.
- A. Using @@ERROR in nested stored procedures requires checking the variable after every individual statement, as @@ERROR resets to 0 after each successful statement, resulting in significantly more custom boilerplate code compared to TRY...CATCH.
- C. Using @@ERROR in the called stored procedures still requires manual checking after each individual T-SQL statement, which does not minimize custom code and is error-prone since the value is lost if not immediately captured.
- D. RAISERROR is used to generate or re-raise error messages but is not itself an error-handling construct; it does not catch or intercept errors and would require additional logic alongside @@ERROR or TRY...CATCH, increasing custom code.
Concept tested. T-SQL TRY CATCH error handling in stored procedures
Reference. https://learn.microsoft.com/en-us/sql/t-sql/language-elements/try-catch-transact-sql
Topics
Community Discussion
No community discussion yet for this question.