Wednesday, October 12, 2011
T-SQL Try - Catch Error Messaging
ALTER FUNCTION portal.fnGetErrorTryCatch ()
RETURNS VARCHAR (MAX)
AS
BEGIN
/*************************************************************************
Joe Kelly
2011-10-12 17:18:44.707
Standard error response for when using try/catch blocks that stays
in scope
Syntax:
BEGIN TRY
SELECT 2/0
END TRY
BEGIN CATCH
SELECT portal.fnGetErrorTryCatch ()
END CATCH
*************************************************************************/
DECLARE @error VARCHAR (MAX)
SELECT @error = 'ERROR_LINE: ' + CAST (ISNULL (ERROR_LINE(), 0) AS VARCHAR (MAX))
+ ' | ERROR_MESSAGE: ' + ISNULL (ERROR_MESSAGE(), 0)
+ ' | ERROR_NUMBER: ' + CAST (ISNULL (ERROR_NUMBER(), 0) AS VARCHAR (MAX))
+ ' | ERROR_PROCEDURE: ' + ISNULL (ERROR_PROCEDURE(), 0)
+ ' | ERROR_SEVERITY: ' + CAST (ISNULL (ERROR_SEVERITY(), 0) AS VARCHAR (MAX))
+ ' | ERROR_STATE: ' + CAST (ISNULL (ERROR_STATE(), 0) AS VARCHAR (MAX)) ;
RETURN @error
END
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment