Hy, you guys!
I'm trying to implement in a trigger write by-me error handling with TRY...CATCH, but I'm loosing a lot of time without success. :'(
Here there's a simple code write for test:
ALTER TRIGGER [dbo].[INS_AlarmsEvents]
ON [dbo].[TEST]
AFTER INSERT, UPDATE
AS
BEGIN TRY
RAISERROR (N'This is message %s %d.', -- Message text.
10, -- Severity,
1, -- State,
N'number', -- First argument.
5); -- Second argument.
END TRY
BEGIN CATCH
INSERT INTO gestioneimpianti.dbo.Errors([ERROR_NUMBER],[ERROR_SEVERITY],[ERROR_STATE],[ERROR_PROCEDURE],[ERROR_LINE],[ERROR_MESSAGE])
VALUES(
(SELECT ERROR_NUMBER() AS ErrorNumber),
(SELECT ERROR_SEVERITY() AS ErrorSeverity),
(SELECT ERROR_STATE() as ErrorState),
(SELECT ERROR_PROCEDURE() as ErrorProcedure),
(SELECT ERROR_LINE() as ErrorLine),
(SELECT ERROR_MESSAGE() as ErrorMessage)
)
END CATCH
I think the code between BEGIN CATCH...END CATCH are not execute, because I find table "Errors" empty.
Anyone can help me? :)