I have stored procedure in SQL Server 2012 say spXample and a scaler-valued function say fXample.
I call a function fXample from spXample.
Can I throw an exception in function and catch it in stored procedure's Catch
block and rethrow to the calling C# code?
Update:
The function I wrote like:
CREATE FUNCTION dbo.fXample(@i INT)
RETURNS TINYINT
AS
BEGIN
RETURN (SELECT CASE WHEN @i < 10
THEN THROW 51000,'Xample Exception',1;
ELSE (SELECT @i)
END);
END
GO
I am getting error
Msg 443, Level 16, State 14, Procedure fXample, Line 46 Invalid use of a side-effecting operator 'THROW' within a function.
How do I write alternative code to achieve above functionality?