Hi All,
I thought I'd try using throw instead of raiseerror in my application, to try to remove the dependency on sys.messages. However I'm having problems with the syntax.
I'm trying to throw the error from within and "if" block. However the only way I've been able to get it to work is with the following fairly clumsy looking syntax. I'm sure there must be a better way...
if not (@EffectiveAccess & [dbo].[fnc_access_write]()) = [dbo].[fnc_access_write]()
begin
begin try
THROW 50001,N'The current user does not have permission to access this resource.',1;
end try
begin catch
throw
end catch
return 0;
end
If I put the throw statement directly within the "begin ... end" of the "if" block then I get an error...
"Incorrect syntax near 'THROW'. Expecting CONVERSATION, DIALOG, DISTRIBUTED, or TRANSACTION."
This suggests that it's trying to combine it with the "begin" statement.
What I want to do is throw the error within a stored procedure, so that I can catch it in my application code. The above works, but it just seems like a bit of a clunky way to have to do it.
I haven't been able to find any samples where "throw" has been used this way, so I'm not sure how it's actually supposed to be done.
Thanks,
Eugene