Occasionally my users will try to perform an action and be presented with an
exception raised directly from SQL Server, in example:
SET @err = 'a user-friendly error condition message'
RAISERROR(@err, 16, 1, 1)
RETURN
The exception type thrown is a System.Data.SqlClient.SqlException, and its
message property holds the exception text. Works well for the most part.
However, a lot of times the SQL error conditions happen after a trigger is
fired, and I tend to place informational PRINT statements in my triggers so
I know what they are doing and when. So to give a simplified example to
reproduce this condition...
PRINT 'some non-user-friendly information...'
PRINT 'more non-user-friendly information...'
SET @err = 'a user-friendly error condition message'
RAISERROR(@err, 16, 1, 1)
RETURN
Now the message property in the corresponding
System.Data.SqlClient.SqlException will contain not only the error text, but
(inexplicably) all the PRINT statements before it, even ones made from other
stored procedures and triggers. I don't want users seeing these things as it
confuses them. I can't just chop everything off after the first line because
some multi-line error messages are legitimate to parse and pass to users. Is
there any way I can keep PRINT messages out of the exception text, or will I
have to do something ugly like prefix all PRINT statements with a character
I can parse out later?
Paul