Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Suppress exception
Message
De
08/01/2014 11:57:43
 
 
À
08/01/2014 10:10:20
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01591488
Message ID:
01591507
Vues:
30
I would unnest the try-catch. Put the specific catch first, the most generic last.

>Hi
>Actually, I am using 3rd party tool which I guess having TRY...CATCH in place, and scoped in calling corresponding base method and event.
>I have code that respond to the event, which will call response.End() as below
>
>Even though I have suppressed the ThreadAbortedException, but somehow the caller program still able to catch it, and show an error message. I tried to change response.End to /HttpContext.Current.ApplicationInstance.CompleteRequest(), but it have another issue that the execution will be continue, which shouldn't once "Redirect" called. Therefore, I am thinking any possible to "hide" the exception from caller program.
>
>
>
>            try
>            {
>                HttpResponse response = HttpContext.Current.Response;
>                Page p = HttpContext.Current.Handler as Page;
>
>                if (p == null) throw new Exception("Page is not an object");
>
>                string resolvedUrl = p.ResolveUrl(url);
>
>                response.Buffer = true;
>                response.Status = "302 Object moved";
>                response.AddHeader("Location", resolvedUrl);
>                response.Write("<HTML><Head>");
>                response.Write("<META HTTP-EQUIV=Refresh CONTENT=\"2;URL=" + resolvedUrl + "\">");
>                response.Write("<Script>window.location='" + resolvedUrl + "';</Script>");
>                response.Write("</Head>");
>                response.Write("</HTML>");
>
>                try
>                {
>                    response.End();
>
>                    //-- Remarked as the code after this method will be still executed.
>                    //-- We always want to stop any execution after "redirect"
>                    //HttpContext.Current.ApplicationInstance.CompleteRequest();
>                }
>                catch
>                { 
>                    //-- To Prevent warning msg logged in event viewer
>                }
>            }
>            catch (ThreadAbortException exc)
>            {
>                // This should be first catch block i.e. before generic Exception
>                // This Catch block is to absorb exception thrown by Response.End
>            }
>            catch (Exception exc)
>            {
>                // Write actual error handling code here
>            }
>
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform