September 24, 2012 at 3:39 am
Hi,
I need to get sql statement, which throws an exception while executing in try block.
E.g.
Begin Try
SELECT 1/0
End Try
Begin Catch
Select ERROR_MESSAGE()
End Catch
Result should like this-
Error Message: Divide by zero error encountered.
SQL Statement: SELECT 1/0
Can anybody help me out to get this result?
Thanks & Regards,
Kumar Anand
September 24, 2012 at 3:45 am
you can use SELECT ERROR_LINE() to get the line the error occurred on.
September 24, 2012 at 3:47 am
I assume that you are using a log table and in the catch block you want to log the information. In that case you can also use the error_line() and error_procedure() function to get the procedure's name and at what line the error occurred.
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply