Compartir a través de


Uso de Intentar..Capturar en procedimientos almacenados compilados de manera nativa

Puede usar bloques try...catch dentro de un procedimiento almacenado compilado de forma nativa. Se admiten las siguientes construcciones:

  • LÍNEA_DE_ERROR

  • MENSAJE_DE_ERROR

  • ERROR_NUMBER

  • PROCEDIMIENTO_DE_ERROR

  • ERROR_SEVERITY

  • ESTADO_DE_ERROR

CREATE PROCEDURE test_try_catch  
with native_compilation, schemabinding, execute as owner   
as  
begin atomic with (transaction isolation level = snapshot, language = N'us_english')  
  
  BEGIN TRY  
    -- generate error  
    declare @i int = 1,  
    @j int = 0  
    select @i/@j  
  END TRY  
  BEGIN CATCH  
    -- Execute error retrieval routine.  
    SELECT  
    ERROR_SEVERITY() AS ErrorSeverity  
    ,ERROR_STATE() AS ErrorState  
    ,ERROR_PROCEDURE() AS ErrorProcedure  
    ,ERROR_LINE() AS ErrorLine  
    ,ERROR_MESSAGE() AS ErrorMessage  
  END CATCH  
end  
go  
  
exec test_try_catch  
go  

Véase también

Procedimientos almacenados compilados de forma nativa