I am using a TRY CATCH block in a stored procedure where I have two INSERT instructions.
If something goes wrong, the CATCH block takes care of rolling back all changes made and it works fine, except one thing!
The exception caught by my ASP.NET application is a SqlException with number 50000. This is not the original number! (the number I was expecting was a 2627)
In the Message property of the exception I can see the original exception number and message formated.
How can I get the original exception number?
try
{
// ... code
}
catch
(SqlException sqlException)
{
switch (sqlException.Number)
{
// Name already exists
case 2627:
throw new ItemTypeNameAlreadyExistsException();
// Some other error
// As the exception number is 50000 it always ends here!!!!!!
default:
throw new ItemTypeException();
}
}
Right now the return value is already being used. I guess that I could use an output parameter to get the exception number, but is that a good idea?
What can I do to get the exception number? Thanks
PS: This is needed because I have two INSERT instructions.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…