Adam
Adam

Reputation: 2455

THROW vs. RAISERROR

I am trying to execute the following code:

THROW 51051, 'I come from the THROW construct :)', 1 ;

The error I am getting is:

Could not find stored procedure 'THROW'.

Isn't the THROW procedure a sytem procedure? Why can't it find it?

Furthhermore, what is the difference between unsing THROW and ErrorState ? Is one older/newer/better than the other? And what do "ErrorSeverity" and "ErrorState" mean by ErrorState? Can I define them as I will or they are predefined?

Upvotes: 31

Views: 48804

Answers (2)

Eduardo Cuomo
Eduardo Cuomo

Reputation: 18937

According to the Differences Between RAISERROR and THROW in Sql Server:

Both RAISERROR and THROW statements are used to raise an error in Sql Server.

The journey of RAISERROR started from Sql Server 7.0; whereas the journey of the THROW statement has just begun with Sql Server 2012.

Microsoft is suggesting we start using the THROW statement instead of RAISERROR. The THROW statement seems to be simpler and easier to use than RAISERROR.

Upvotes: 31

podiluska
podiluska

Reputation: 51494

Yes, it is, but only since 2012. If you're using 2008R2, then it didn't exist.

The definitions of state and severity are clearly documented in the raiserror documentation

Upvotes: 10

Related Questions