Home » Interview Q & A » Q12. What is RAISERROR()? Where do you use this?

Q12. What is RAISERROR()? Where do you use this?

Our Categories

Blog Stats

  • 33,751 hits

Calendar

June 2013
M T W T F S S
« May    
 12
3456789
10111213141516
17181920212223
24252627282930

Please visit SQLVERSITY.COM for more details.

The name itself RAISERROR is saying that, we are raising an error. Mostly we use RAISERROR with exceptional handling of stored procedures, SQL scripts. In SQL Server we have ERROR_MESSAGE() function to display error messages. But sometimes it might not give meaningful error message.

So by using RAISERROR function, we can overwrite the error message in a meaningful way.

Ex:

———————————————————————————————————————

BEGIN TRY

DECLARE @RaiserrorDemo INT

SET @RaiserrorDemo = 8/0

END TRY

BEGIN CATCH

RAISERROR (‘Divided by zero exception. We can not divide a number with zero.’, 16, 1)

— 16 — Error Severity

—  1 — Error state

END CATCH

GO

——————————————————————————————————————— 

Error Raised by the above ex:

Msg 50000, Level 16, State 1, Line 9

Divided by zero exception. We can not divide a number with zero.

———————————————————————————————————————

For more information about RAISERROR, Click here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: