title: T-SQL Throw Exception
body: <p>I am facing the famous 'Incorrect syntax' while using a <code>THROW</code> statement in a T-SQL stored procedure. I have Googled it and checked the questions on StackOverflow but the solutions proposed (and strangely, accepted) do not work for me.</p>
  
  <p>I am modifying a stored procedure as follows:</p>
  
  <pre class="lang-sql prettyprint-override"><code>ALTER PROCEDURE [dbo].[CONVERT_Q_TO_O]
      @Q_ID int = NULL,
      @IDENTITY INT = NULL OUTPUT
  AS
  BEGIN
      SET NOCOUNT ON;
  
      DECLARE @EXISTING_RECORD_COUNT [int];
  
      SELECT
          @EXISTING_RECORD_COUNT = COUNT (*)
      FROM
          [dbo].[O]
      WHERE
          [Q_ID] = @Q_ID
  
      IF @EXISTING_RECORD_COUNT = 0
      BEGIN
          -- DO SOME STUFF HERE
  
          -- RETURN NEW ID
          SELECT @IDENTITY = SCOPE_IDENTITY()
      END
      ELSE
      BEGIN
           THROW 99001, 'O associated with the given Q Id already exists', 1;
      END
  END
  GO
  </code></pre>
  
  <p>When I code this T-SQL I get an error saying </p>
  
  <blockquote>
    <p>Incorrect statement near 'THROW'. Expecting CONVERSATION, DIALOG, DISTRIBUTED, or TRANSACTION</p>
  </blockquote>
  
  <p>All solutions suggest to put a semi-colon either before 'THROW' or after 'ELSE BEGIN' statements. When I modify the T-SQL I simply get the "<strong><em>Incorrect statement near 'THROW'</em></strong>" error and can't seem to find a solution.</p>
  
  <p>Any suggestions?</p>