error that occur in StoredProcedure it's cause exception or not?

  • Thread starter Thread starter mttc
  • Start date Start date
M

mttc

error that occur in StoredProcedure it's cause exception or not? and
when I need to use with @@error?
 
yes errors with a certain severity level will throw exceptions in your code

try this in your stored proc

RAISEERROR(N'This is a message %s %d', -- message text
16, --severity
1, --state
N'number', --first argument
5); --second argument

and in your code you can get this error message in the SqlException object

try
{
ExecuteSP();
}
catch(SqlException ex)
{
Console.WriteLine(ex); //ex.Message will have the message text you used in
raiseerror
}

for details on RAISEERROR check the following url
http://msdn2.microsoft.com/en-us/library/ms177497.aspx

note: not all errors in SP / RAISEERROR throw exceptions in code... check
the severity levels to confirm
 
Back
Top