How to retrieve an error from SQL

Hello,

I am trying to retrieve errors from SQL like so:


DECLARE @debugerrormsg nvarchar(MAX)

BEGIN 
	SELECT L.ID, L.Name FROM Lookup L WHERE L1.ID = 1
END 
END TRY 
BEGIN CATCH
SET @debugerrormsg = '' + ERROR_MESSAGE() + ' at line ' + cast(ERROR_LINE() as varchar)
RAISERROR(@debugerrormsg, 16, 16)
END CATCH

So you can see that “L1” is wrong so this i’m expecting to output the error and the line number but it does not work. For some reason it does not show the line number…

Any ideas what i’m doing wrong?

Kind regards,