在SQL Server的try...catch语句中获取错误消息代码的的语句

前端之家收集整理的这篇文章主要介绍了在SQL Server的try...catch语句中获取错误消息代码的的语句前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="19102" class="copybut" id="copybut19102" onclick="doCopy('code19102')"> 代码如下:

<div class="codebody" id="code19102">
BEGIN TRY
...
...
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT; SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE(); RAISERROR (@ErrorMessage,-- Message text.
@ErrorSeverity,-- Severity.
@ErrorState -- State.
);
END CATCH;

猜你在找的MsSQL相关文章