title: How do I raise an error that SQL will see as a job failure?
body: <p>I've got a job scheduled through the SQL Server Agent that runs a sproc which runs some other sprocs. Every sproc looks like this:</p>
  
  <pre><code>BEGIN TRY
      -- do stuff
  END TRY
  BEGIN CATCH
      DECLARE @errorMessage varchar(4000)
      DECLARE @procName varchar(255)
      SELECT @errorMessage = error_message()
      SELECT @procName = OBJECT_NAME(@@PROCID)
  
      RAISERROR('%s threw an exception: %s', 16, 1, @procName, @errorMessage)
  END CATCH
  </code></pre>
  
  <p>This all works fine - errors are raised and thrown up the stack, life is good. However, my RAISERROR calls don't appear to cause the job to fail - I'm set to receive an e-mail notification "When the job fails," but never receive one. E-mail notifications are working, as I will get emails if I change the notification to "when the job succeeds". Is there some other function I should be using here in place of RAISERROR?</p>