Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

THROW - 1 Expand / Collapse
Author
Message
Posted Wednesday, February 20, 2013 5:29 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 10:00 AM
Points: 8,551, Visits: 9,043
Nice interesting question.

I really must upgrade and get SQL2012 so that I can start playing with this stuff instead of just reading about it.

If people have run the code and got 14 for erros state, what's going on? I would expect to see 14 only if THROW was called without any parameters (to rethrow the previous error).


Tom
Post #1422031
Posted Wednesday, February 20, 2013 7:47 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 7:35 AM
Points: 1,826, Visits: 1,359
L' Eomot Inversé (2/20/2013)
Nice interesting question.

I really must upgrade and get SQL2012 so that I can start playing with this stuff instead of just reading about it.


+ 1

Thanks for the question on a 2012 feature.




Everything is awesome!
Post #1422093
Posted Wednesday, February 20, 2013 9:04 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 3:21 PM
Points: 1,210, Visits: 2,512
L' Eomot Inversé (2/20/2013)
Nice interesting question.

I really must upgrade and get SQL2012 so that I can start playing with this stuff instead of just reading about it.

If people have run the code and got 14 for erros state, what's going on? I would expect to see 14 only if THROW was called without any parameters (to rethrow the previous error).


I think people said they got severity level 14, not error state 14. They must be looking at the results of the SELECT in the CATCH block, which does show Level = 14, rather than the error message returned by the THROW statement, which always shows "Level 16" as its defined behavior.


Jason Wolfkill
Blog: SQLSouth
Twitter: @SQLSouth
Post #1422135
Posted Wednesday, February 20, 2013 9:35 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 1:02 PM
Points: 1,276, Visits: 2,197
Awesome, thanks for the question on new 2012 functionality.
Post #1422155
Posted Wednesday, February 20, 2013 10:27 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 6:21 AM
Points: 1,338, Visits: 1,506
I'm having a senior blonde moment here...

What is the difference between:
THROW returns the same error message as the select statement
and
THROW returns the error message "why oh why do you do this"
Post #1422197
Posted Wednesday, February 20, 2013 11:07 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 6:57 PM
Points: 3,258, Visits: 1,954
Thanks for the 2012 question.
Post #1422220
Posted Wednesday, February 20, 2013 11:18 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 3:21 PM
Points: 1,210, Visits: 2,512
batgirl (2/20/2013)
I'm having a senior blonde moment here...

What is the difference between:
THROW returns the same error message as the select statement
and
THROW returns the error message "why oh why do you do this"


The SELECT statement returns one row with four columns. The value in the unnamed fourth column is the text returned by the ERROR_MESSAGE() function, i.e., the standard "violation of primary key" message.

The THROW statement doesn't return rows but generates a message that includes the string 'why oh why do you do this', which was the [message] argument to the THROW statement.

THROW therefore does not return the same "error message" as the SELECT, but does return "why oh why do you do this".

Does that clear it up?


Jason Wolfkill
Blog: SQLSouth
Twitter: @SQLSouth
Post #1422224
Posted Wednesday, February 20, 2013 11:40 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 6:21 AM
Points: 1,338, Visits: 1,506
wolfkillj (2/20/2013)
batgirl (2/20/2013)
I'm having a senior blonde moment here...

What is the difference between:
THROW returns the same error message as the select statement
and
THROW returns the error message "why oh why do you do this"


The SELECT statement returns one row with four columns. The value in the unnamed fourth column is the text returned by the ERROR_MESSAGE() function, i.e., the standard "violation of primary key" message.

The THROW statement doesn't return rows but generates a message that includes the string 'why oh why do you do this', which was the [message] argument to the THROW statement.

THROW therefore does not return the same "error message" as the SELECT, but does return "why oh why do you do this".

Does that clear it up?


Yes - I was woefully short on caffeine when I wondered this.
Some days "senior" and "blonde" is an insurmountable combination

Thanks so much!
Post #1422229
Posted Wednesday, February 20, 2013 12:49 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 1:39 PM
Points: 212, Visits: 223
wolfkillj (2/20/2013)
L' Eomot Inversé (2/20/2013)
Nice interesting question.

I really must upgrade and get SQL2012 so that I can start playing with this stuff instead of just reading about it.

If people have run the code and got 14 for erros state, what's going on? I would expect to see 14 only if THROW was called without any parameters (to rethrow the previous error).


I think people said they got severity level 14, not error state 14. They must be looking at the results of the SELECT in the CATCH block, which does show Level = 14, rather than the error message returned by the THROW statement, which always shows "Level 16" as its defined behavior.


Hey from BOL, I was infering that when THROW is used in a catch block without any parameters, it returns the level of the actual error raised in the try block and not 16...

Please let me know if I am right?










___________________________________________________________________
If I can answer a question then anyone can answer it..trying to reverse the logic..
Post #1422255
Posted Wednesday, February 20, 2013 1:58 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 3:21 PM
Points: 1,210, Visits: 2,512
venkat9.sql (2/20/2013)
wolfkillj (2/20/2013)
L' Eomot Inversé (2/20/2013)
Nice interesting question.

I really must upgrade and get SQL2012 so that I can start playing with this stuff instead of just reading about it.

If people have run the code and got 14 for erros state, what's going on? I would expect to see 14 only if THROW was called without any parameters (to rethrow the previous error).


I think people said they got severity level 14, not error state 14. They must be looking at the results of the SELECT in the CATCH block, which does show Level = 14, rather than the error message returned by the THROW statement, which always shows "Level 16" as its defined behavior.


Hey from BOL, I was infering that when THROW is used in a catch block without any parameters, it returns the level of the actual error raised in the try block and not 16...

Please let me know if I am right?


I don't think that's right. BOL specifies that THROW can be called without parameters only in a CATCH block, and also that severity is ALWAYS set to 16 with THROW.
Source: http://msdn.microsoft.com/en-us/library/ee677615.aspx


Jason Wolfkill
Blog: SQLSouth
Twitter: @SQLSouth
Post #1422292
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse