Sage.Project.Application_Error C# (CSharp) Method

Application_Error() protected method

Handles the Error event of the Application control.
protected Application_Error ( object sender, EventArgs e ) : void
sender object The source of the event.
e System.EventArgs The instance containing the event data.
return void
        protected virtual void Application_Error(object sender, EventArgs e)
        {
            Exception exception = this.Server.GetLastError();
            if (exception == null)
                return;

            if (exception is ThreadAbortException)
                return;

            log.Fatal(exception.Message, exception);

            StringBuilder html = new StringBuilder();
            TextWriter writer = new StringWriter(html);
            SageContext context = new SageContext(this.Context);

            SageException sageException = SageHelpException.Create(exception);
            if (((SageHelpException) sageException).Problem.Type == ProblemType.Unknown)
                sageException = exception is SageHelpException
                ? (SageHelpException) exception
                : new SageException(exception);

            if (this.IsRequestAvailable)
            {
                sageException.Render(writer, context);
            }
            else
            {
                sageException.RenderWithoutContext(writer);
            }

            writer.Close();
            writer.Dispose();

            this.Response.ContentType = "text/html";
            this.Response.Write(html.ToString());
            this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            this.Response.Cache.SetNoStore();
            this.Response.End();
        }