I am trying to design a high quality set of library stored procedures
in MSSQL 2005. My issue at hand is I don't know the best way to
design error handling. For example, suppose I have the following
stack of executed stored procedures in TSQ:
Client (C# .NET)
> PrimaryStoredProcedure (BEGIN/END TRANSACTION)
> LibraryStoredProcedureA
> LibraryStoredProcedureB (RAISERROR ...)
LibraryStoredProcedureB does a RAISERROR and then RETURN. But this
design requires LibraryStoredProcedureA to check for the @@ERROR and
then RETURN, and then PrimaryStoredProcedure to somehow check the
@ERROR (even thought it was cleared) and ROLLBACK.
It just seems like a lot of work. The only good alternative I've come
up with is to wrap each stored procedure in a TRY/CATCH, and then
"rethrow" it back to the caller (even though there doesn't seem to be
any way to rethrow in TSQL). I know you can rethrow by calling
RAISERROR again, as shown at
http://sqlblog.com/blogs/roman_rehak/archive/2007/12/01/how-to-rethrow...rors-in
but for system exceptions I now lose the severity.
If a RAISERROR occurs, ultimately I want the Client to get the
exception.
Is there a better way to implement this than what I've just outlined?