Https://msdn.microsoft.com/zh-cn/library/ms178600.aspx
Returns the line number where the error occurred, causing the run TRY ... Catch block for the catch construct.
GrammarError_line ()
return value
When called in a CATCH block:
Returns the line number where the error occurred.
If the error occurs in a stored procedure or trigger, the line number in the routine is returned.
If called outside the scope of the CATCH block, NULL is returned.
Example
A. Using Error_line in a CATCH block
The following code example shows a SELECT statement that generates a 0 exception error . returns the line number where the error occurred.
1. BEGIN TRY2. --Generate a divide-by-zero error.3. SELECT 1/0; END trybegin CATCH SELECT error_line () as ErrorLine; END CATCH; GO
The empty line in front of the begin try is also counted, as shown in the following test:
B. With stored procedures use Error_line in CATCH blocks
The following code example shows a stored procedure that generates a 0 exception error. Error_line Returns the line number in the stored procedure where the error occurred.
--Verify that the stored procedure does not already exist. IF object_id (' Usp_exampleproc ', ' P ') is not NULL DROP PROCEDURE usp_exampleproc; go--Create A stored procedure that-generates a Divide-by-zero error. CREATE PROCEDURE usp_exampleprocas SELECT 1/0; Gobegin try -Execute the stored procedure inside the try block. EXECUTE Usp_exampleproc; END trybegin CATCH SELECT error_line () as ErrorLine; END CATCH; GO
The result shows that the line number is calculated from the go
C. Using Error_line in CATCH blocks with other error handling tools
The following code example shows a SELECT statement that generates a 0 exception error . the information about the error is returned with the line number where the error occurred.
BEGIN TRY --Generate a divide-by-zero error. SELECT 1/0; END trybegin CATCH SELECT error_number () as ErrorNumber, error_severity () as errorseverity, error_ State () as ErrorState, error_procedure () as Errorprocedure, error_line () as ErrorLine, error_message () as errormessage; END CATCH; GO
Results
Error_line is a great help when we debug the location query error.
SQL Server Error Line number