title: SQL Server: Rethrow exception with the original exception number
body: <p>I am using a TRY CATCH block in a stored procedure where I have two INSERT instructions.</p>
  
  <p>If something goes wrong, the CATCH block takes care of rolling back all changes made and it works fine, except one thing!</p>
  
  <p>The exception caught by my ASP.NET application is a SqlException with number 50000. This is not the original number! (the number I was expecting was a 2627)</p>
  
  <p>In the Message property of the exception I can see the original exception number and message formated.</p>
  
  <p>How can I get the original exception number?</p>
  
  <pre><code>try
  {
      // ... code
  }
  catch
  (SqlException sqlException)
  {
      switch (sqlException.Number)
      {
          // Name already exists
          case 2627:
              throw new ItemTypeNameAlreadyExistsException();
  
          // Some other error
          // As the exception number is 50000 it always ends here!!!!!!
          default:
              throw new ItemTypeException();
      }
  }
  </code></pre>
  
  <p>Right now the return value is already being used. I guess that I could use an output parameter to get the exception number, but is that a good idea?</p>
  
  <p>What can I do to get the exception number? Thanks</p>
  
  <p><strong>PS: This is needed because I have two INSERT instructions.</strong></p>