home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 18,333 of 19,505   
   Gene Wirchenko to esquel@sommarskog.se   
   Re: SSE 2008: Transactions and Rollbacks   
   19 May 11 23:20:51   
   
   XPost: microsoft.public.sqlserver.programming   
   From: genew@ocis.net   
      
   On Thu, 19 May 2011 23:38:29 +0200, Erland Sommarskog   
    wrote:   
      
   >Gene Wirchenko (genew@ocis.net) writes:   
   >>      It does not say why it normally does.  I think the reason is that   
   >> a raiserror() with a severity >=11 triggers the catch block, but it is   
   >> not documented (that I can see).   
   >   
   >RAISERROR should invokes the CATCH block, so much is right. This is   
   >applies to both triggers and regular code.   
      
        Nope.  If the severity is <=10, then raiserror() will not result   
   in the catch block triggering.  This is documented.  I do not know why   
   it is this way, but it is.   
      
        Try the following code.  Besides labelling, the only difference   
   between the two procedures is the severity in the raiserror().   
      
   ***** Start of Code *****   
   use tempdb   
   go   
      
   if object_id(N'HighSeverity',N'P') is not null   
      drop procedure HighSeverity   
   if object_id(N'LowSeverity',N'P') is not null   
      drop procedure LowSeverity   
   go   
      
   create procedure HighSeverity   
   as   
      begin try   
      print N'In HighSeverity'   
      raiserror(N'This is a severe error.',11,1)   
      print N'Catch did not trigger.'   
      end try   
      begin catch   
      print N'Catch triggered.'   
      end catch   
      
   go   
      
   create procedure LowSeverity   
   as   
      begin try   
      print N'In LowSeverity'   
      raiserror(N'This is a mild error.',10,1)   
      print N'Catch did not trigger.'   
      end try   
      begin catch   
      print N'Catch triggered.'   
      end catch   
      
   go   
      
   execute HighSeverity   
   execute LowSeverity   
   ***** End of Code *****   
      
        The output will be:   
      
   In HighSeverity   
   Catch triggered.   
   In LowSeverity   
   This is a mild error.   
   Catch did not trigger.   
      
   >As for what is documented or not is this madhouse I don't know. I only   
   >know that the updated version of my article on error handling is long   
   >overdue...   
      
   Sincerely,   
      
   Gene Wirchenko   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca