Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Begin Try exec @sql End Try Begin Catch Display error message (How to?) return End Catch
Now, on error with the exec @sql statement, I want it to display the error message first and then end the code.
declare @sql varchar(100) = 'Select 1/0' Begin Try exec(@sql) End Try
Begin Catch print 'error='+ERROR_MESSAGE() return End Catch
Add a comment
To get the error message generated by system
declare @sql varchar(100) = 'Select 1/0' Begin Try exec(@sql) End Try Begin Catch print ERROR_MESSAGE() return
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.