Re: how to catch custom errors raised in SP gracefully?
From: Bob (bobatkpmg_at_yahoo.com)
Date: 07/13/04
- Next message: Jeremy: "Cannot create a table and a stored procedure in the same script?"
- Previous message: Angel: "JSCript and Data Access"
- In reply to: Mary Chipman: "Re: how to catch custom errors raised in SP gracefully?"
- Next in thread: Mary Chipman: "Re: how to catch custom errors raised in SP gracefully?"
- Reply: Mary Chipman: "Re: how to catch custom errors raised in SP gracefully?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 13 Jul 2004 14:42:44 -0500
Hi Mary:
I think this fits my need the best. However, I can't get the event handler
to throw a new exception, nothing happens. But if I put in
Console.Writeline, or HttpResponse.Write(), the error message from the event
argument can be printed out. Do you know why? Here's my code snippet:
private static void OnInfoMessage(object sender, SqlInfoMessageEventArgs
e) {
System.Web.HttpContext.Current.Response.Write(e.Message + e.Source +
e.Errors.Count.ToString() + "Bob");
throw new Exception("Blah"); //This doesn't throw an exception.
}
And in my function that actually does the call to the DB, I have this:
....................
liveCmd.Connection.InfoMessage += new
SqlInfoMessageEventHandler(OnInfoMessage);
DataSet ds = DataHelper.ExecuteSelectQuery(liveCmd, string.Empty);
....................
"Mary Chipman" <mchip@online.microsoft.com> wrote in message
news:s888f0d6njdhdkl5k39qvg20j3qessu4ub@4ax.com...
> One way to handle it is to use output parameters instead of RAISERROR
> to handle both server and user-defined errors. Raising exceptions is
> always expensive, and coding your stored procedures to minimize
> sending error messages back and forth across the wire is a good idea.
> Anything that can be handled on the server should be, and the client
> should get back a clear success/failure message for every operation
> performed so that it can branch accordingly.
>
> --Mary
>
> On Tue, 13 Jul 2004 12:44:21 -0500, " Bob" <bobatkpmg@yahoo.com>
> wrote:
>
> >In my stored procedure, I raise an error using RAISERROR. Seems it just
> >comes out to the .NET code as a SqlException. Is there a way to
> >differentiate my custom error from the raw SqlExceptions (like table is
> >missing, FK violation etc), because if I purposely raise an error, I sure
> >want to handle it differently.
> >
> >Thanks
> >Bob
> >
>
- Next message: Jeremy: "Cannot create a table and a stored procedure in the same script?"
- Previous message: Angel: "JSCript and Data Access"
- In reply to: Mary Chipman: "Re: how to catch custom errors raised in SP gracefully?"
- Next in thread: Mary Chipman: "Re: how to catch custom errors raised in SP gracefully?"
- Reply: Mary Chipman: "Re: how to catch custom errors raised in SP gracefully?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|