Re: how to catch custom errors raised in SP gracefully?

From: Bob (bobatkpmg_at_yahoo.com)
Date: 07/13/04


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
> >
>



Relevant Pages

  • RE: Biztalk 2006 Tutorial 3
    ... There are some known issues w/ the tutorials. ... Below is the error message that appears in the event ... Exception type: ServiceCreationException ... md, Objectargs, Object server, Int32 methodPtr, Boolean fExecuteInContext, ...
    (microsoft.public.biztalk.general)
  • RE: Concerns about exception string revealing internals/data about
    ... exceptions could return certain information as part of the error message. ... exception occurs in my program, is it possible that the exception error ... built in ADO objects in Visual Studio for Microsoft SQL Server. ... the build-in controls in SQL Server2000 or .Net winform/Asp.net controls? ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Concerns about exception string revealing internals/data about
    ... Sorry in last post I meant an "unhandled" exception should never be shown to ... exceptions could return certain information as part of the error message. ... built in ADO objects in Visual Studio for Microsoft SQL Server. ... the build-in controls in SQL Server2000 or .Net winform/Asp.net controls? ...
    (microsoft.public.dotnet.framework.clr)
  • RE: Biztalk 2006 Tutorial 3
    ... Below is the error message that appears in the event ... Exception type: ServiceCreationException ... Microsoft.BizTalk.XLANGs.BTXEngine.BTXSession._createOrRehydrateRealService(Guid& instanceId, IBTMessage currMsg) ... md, Objectargs, Object server, Int32 methodPtr, Boolean fExecuteInContext, ...
    (microsoft.public.biztalk.general)
  • RE: Single Sign-On User Credentials Question
    ... error message means that GetCredentialEntryURL can't find an Enterprise ... different EA names in its calls to GetCredentials and GetCredentialEntryURL. ... This seems to indicate that it can't find the login URL for my application. ... I get the same error message when an unhandled exception occurrs. ...
    (microsoft.public.sharepoint.portalserver)