Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Try/Catch syntax with the exact error
Message
From
05/03/2008 10:04:54
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01298895
Message ID:
01298905
Views:
19
>From BOL:
>
>USE AdventureWorks;
>GO
>
>-- Verify that the stored procedure does not exist.
>IF OBJECT_ID ('usp_GetErrorInfo', 'P') IS NOT NULL
>    DROP PROCEDURE usp_GetErrorInfo;
>GO
>
>-- Create procedure to retrieve error information.
>CREATE PROCEDURE usp_GetErrorInfo
>AS
>    SELECT
>        ERROR_NUMBER() AS ErrorNumber,
>        ERROR_SEVERITY() AS ErrorSeverity,
>        ERROR_STATE() as ErrorState,
>        ERROR_PROCEDURE() as ErrorProcedure,
>        ERROR_LINE() as ErrorLine,
>        ERROR_MESSAGE() as ErrorMessage;
>GO
>
>BEGIN TRY
>    -- Generate divide-by-zero error.
>    SELECT 1/0;
>END TRY
>BEGIN CATCH
>    -- Execute the error retrieval routine.
>    EXECUTE usp_GetErrorInfo;
>END CATCH;
>GO
>
If I would make intensive use of scripts in the next months, I would certainly benefit of such code.

Thanks
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform