How to handle outofmemoryexception?

Source: Internet
Author: User


Today, I am browsing csdn websites and have encountered errors. If I remember correctly, I often encounter these two errors. Here I don't want to talk about how csdn is losing people's hearts, instead, I want to discuss with you how to solve these two problems (Here we only consider web apps), so that we can avoid this unfriendly problem in our system and even "scare" the appearance of the customer's interface.

1. runtime error
FirstProgramExceptions or even errors are inevitable. However, when a system exception occurs, you should provide a friendly interface and briefly explain the cause.
<Customerrors mode = "off"/> NO configuration is required.
Then, all the errors are detected in the application_error event of httpmodule, and the page jumps to the specified friendly page. In addition, the page can also be detected in the page_error event of the base class of all pages, and the page jumps to the specified friendly page, Asp. I think the solution provided by net forums is already excellent. Bao Yu of the blog hall provides a good introduction in this regard.

Ii. How to Handle outofmemoryexception
Under what circumstances will outofmemonryexception occur? Reference <. net Framework programming version>: when we try to create a new object, and the garbage collector cannot find any available memory, in this case, we can capture this exception. In another case, when the CLR needs memory, but the system cannot provide it, this exception will also be thrown, our application cannot capture this error.

<. Net Framework Program Design revision> lists the outofmemoryexception as an implicit assumption that developers will never consider. That is to say, many developers simply ignore the possibility of the exception and handle it, at least I did not specifically consider this exception in my system.

My current concerns are:
1. If a change exception is thrown if no available memory is found for the new object, can the application_error event of httpmodule capture the change error? My idea is that even if it can be captured, it cannot be processed, because custom exception handling still requires memory to run, so no matter whether it can be captured, it cannot be processed in a friendly way.

2. If the CLR cannot find the required memory and throws a change exception, it cannot be processed.

That is to say, in almost all circumstances, we cannot provide friends with an outofmemoryexception in the system.

Good interface?

Can you discuss and provide your solutions?
Here is a good solution for tips

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.