Answer: SQL Server Denali improves error handling with the new THROW (T-SQL) statement.
THROW outside of a TRY…CATCH block acts similar to the RAISERROR() function, with a
few notable exceptions:
- The message_id parameter doesn’t need to be defined in sys.messages.
- The message_id must be INT (not BIGINT) and greater than or equal to 50000.
- THROW doesn’t accept any parameter substitution for customizing the error message
inline.
- The severity level is always 16.
THROW inside a TRY…CATCH will be able to rethrow the error message that occurred in
the TRY block. The next example shows a division by 0 into a TRY block. When the error
occurs, the execution goes inside the CATCH block, where the error can be handled by
a rollback and/or a notification. Then, the THROW command displays the error:
BEGIN TRY
select 1/0
END TRY
BEGIN CATCH
PRINT N'Message from inside CATCH.';
-- rollback
-- notification
-- throwing the same errors back to the caller
THROW;
END CATCH;
go
Asked In: Many Interviews |
Alert Moderator