gpt4 book ai didi

asp.net - 哪些 Asp.net 异常可以做什么?

转载 作者:行者123 更新时间:2023-12-02 11:12:42 24 4
gpt4 key购买 nike

如果我写这段代码

  protected void Page_Load(object sender, EventArgs e)
{
Page_Load(sender, e);
}

我收到错误(无限递归):

enter image description here

并且w3wp.exe进程从任务管理器终止。

很好...

但是如果我这样做:

throw new ApplicationException(); //or SystemException();

它仅出现在常规异常页面中。 (w3wp.exe 仍在运行)。

问题:

  • 什么样的异常导致w3wp.exe关闭?
  • 什么样的异常会导致应用程序池关闭?

附:根据我刚刚写的内容,请考虑以下场景:我可以编写一个网页,在网站群中托管我的网站,并且我可以通过创建递归来终止整个 w3wp.exe 进程......(其他人也会遇到麻烦)......

你能回答我的问题吗?

谢谢。

最佳答案

这很可能就是著名的StackoverflowException 。这是由无限循环引起的,因为您一次又一次地调用 Page_Load 方法。

来自 MSDN:

In prior versions of the .NET Framework, your application could catch a StackOverflowException object (for example, to recover from unbounded recursion). However, that practice is currently discouraged because significant additional code is required to reliably catch a stack overflow exception and continue program execution.

Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default. Consequently, users are advised to write their code to detect and prevent a stack overflow. For example, if your application depends on recursion, use a counter or a state condition to terminate the recursive loop. Note that an application that hosts the common language runtime (CLR) can specify that the CLR unload the application domain where the stack overflow exception occurs and let the corresponding process continue. For more information, see ICLRPolicyManager Interface and Hosting Overview.

您可能想看看这个答案:

https://stackoverflow.com/a/4802309/284240

关于asp.net - 哪些 Asp.net 异常可以做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191760/

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