Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Try/Catch syntax with the exact error
Message
De
05/03/2008 10:04:54
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01298895
Message ID:
01298905
Vues:
18
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform