1. You are developing a stored procedure in Microsoft Fabric SQL database. The procedure uses a TRY/CATCH block. Inside the CATCH block, the developer writes: ```sql IF XACT_STATE() = -1 ROLLBACK TRANSACTION; ELSE IF XACT_STATE() = 1 ROLLBACK TRANSACTION; ``` After the rollback, the developer wants to re-raise the original error to the calling application. Which statement should be used?
- A. RAISERROR(ERROR_MESSAGE(), ERROR_SEVERITY(), ERROR_STATE());
- B. THROW;✓ Correct
- C. RETURN ERROR_NUMBER();
- D. SELECT ERROR_MESSAGE() AS ErrorMessage;
Explanation
THROW; (with no arguments) re-raises the original exception that was caught, preserving the original error number, severity, state, and message — which is the recommended modern T-SQL approach. RAISERROR with ERROR_MESSAGE() and ERROR_SEVERITY() re-raises a message but does NOT preserve the original error number, and its severity and state are not perfectly preserved either; additionally, severity 20+ requires WITH LOG. RETURN ERROR_NUMBER() simply returns a code to the caller without raising an actual SQL error condition. SELECT ERROR_MESSAGE() outputs the message as a result set, which does not signal an error to the calling application.