Search code examples
sqlsql-serverthrowraiserror

THROW or RAISERROR for specific non-user defined error codes


I'm trying to test some code that traps a specific error code in SQL server. The error code is 7886.

When I try to THROW, I get:

Error number 7886 in the THROW statement is outside the valid range. Specify an error number in the valid range of 50000 to 2147483647.

When I try to RAISERROR, I get:

Error number 7886 is invalid. The number must be from 13000 through 2147483647 and it cannot be 50000.

Is there any way to raise an arbitrary error like this without actually setting up the situation to cause the error in the first place?


Solution

  • As said in the comments of the original question, this is impossible to do in SQL server.

    :(