gpt4 book ai didi

c# - 捕捉 HttpException 是个好主意?

转载 作者:行者123 更新时间:2023-11-30 15:02:57 26 4
gpt4 key购买 nike

我的 output.aspx 页面有时会出现以下错误:

Exception Details: System.Web.HttpException: Request timed out.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): Request timed out.]

捕捉这个异常是个好主意吗?我在哪里执行此操作,因为我的 output.aspx.cs 有一个 Page_Load 并且该函数调用 RunTable()。我应该在该函数内容周围放置一个 try catch block 吗?

最佳答案

在应用层捕获异常

    void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs

// Get the exception object.
Exception exc = Server.GetLastError();

// Handle HTTP errors
if (exc.GetType() == typeof(HttpException))
{
// The Complete Error Handling Example generates
// some errors using URLs with "NoCatch" in them;
// ignore these here to simulate what would happen
// if a global.asax handler were not implemented.
if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
return;

//Redirect HTTP errors to HttpError page
Server.Transfer("HttpErrorPage.aspx");
}

// For other kinds of errors give the user some information
// but stay on the default page
Response.Write("<h2>Global Page Error</h2>\n");
Response.Write(
"<p>" + exc.Message + "</p>\n");
Response.Write("Return to the <a href='Default.aspx'>" +
"Default Page</a>\n");

// Log the exception and notify system operators
ExceptionUtility.LogException(exc, "DefaultPage");
ExceptionUtility.NotifySystemOps(exc);

// Clear the error from the server
Server.ClearError();
}

关于c# - 捕捉 HttpException 是个好主意?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12203741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com