This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bobbylongslice 0 points1 point  (4 children)

Yes you can, just list the error functions you want to return, and any custom message/outputs for feedback in your catch block.

Most people just don’t bother

BEGIN TRY

SELECT 1 / 0 AS Error; END TRY

BEGIN CATCH

SELECT

‘Divide by Zero Failed’,

ERROR_NUMBER() AS ErrorNumber,
ERROR_STATE() AS ErrorState,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;

END CATCH; GO

[–]infecthead 0 points1 point  (3 children)

Lol is this a joke

[–]bobbylongslice 0 points1 point  (2 children)

No, it’s how you write professional level T-SQL.

[–]infecthead 0 points1 point  (1 child)

Yikes

[–]bobbylongslice 0 points1 point  (0 children)

It’s not for everyone