debugsqlMinor
THROW is not returning the correct line number when variables are used
Viewed 0 times
thenumberlineareusedreturningcorrectvariableswhenthrow
Problem
An often mentioned benefit of THROW in a CATCH block is that it returns correct line number where the error occurred.
I noticed that it only does this when I use THROW without any variables.
Using the format below, with my own error number and message returns the line number of the THROW itself (just like RAISERROR does).
Is this to be expected and a known flaw or am I doing something wrong?
I'm using SQL Server 2017 CU20.
I noticed that it only does this when I use THROW without any variables.
Using the format below, with my own error number and message returns the line number of the THROW itself (just like RAISERROR does).
THROW 50055, 'my message', 1;Is this to be expected and a known flaw or am I doing something wrong?
I'm using SQL Server 2017 CU20.
Solution
Is this to be expected and a known flaw or am I doing something wrong?
Yes, it is the expected behavior. You've generated a new error message, and it originates at the call site of
Yes, it is the expected behavior. You've generated a new error message, and it originates at the call site of
THROW .... This is why you should favor just THROW; or you need to encapsulate all the relevant error context information in your message.Context
StackExchange Database Administrators Q#265720, answer score: 7
Revisions (0)
No revisions yet.