Here is my stored procedure code called "uspTest"
BEGIN TRY
SELECT 3 / 0;
END TRY
BEGIN CATCH
RAISERROR('D', 16, 3);
END CATCH
And Here is my c# code in visual studio
public IHttpActionResult RegisterUser(RegisterModelView registerViewModel)
{
try
{
using (AusHerbEntities ctx = new AusHerbEntities())
{
ctx.uspTest();
Console.Write("i am in try block");
}
}
catch (Exception e)
{
Console.Write(e.Message);
}
return Ok();
}
When I run this code, the Catch block in C# code is not called, but I expect it to be called because the Stored Procedure raises error.
How can I get this code work?
I just want to do RAISERROR in catch block in Stored Procedure and catch the error in c# code.