Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 2
    A major problem with OutOfMemoryException is that there's no nice way code can be sure that it "only" indicates the failure of a particular allocation one was prepared to have fail. It's possible that some other more serious exception was thrown, and an OutOfMemoryException occurred during stack unwinding from that other exception. Java may have been late to the party with its "try-with-resources", but it handles exceptions during stack unwinding a bit better than .NET. Commented Apr 21, 2015 at 18:05
  • 1
    @supercat - true enough, but that's pretty much true of any other general System exception, when stuff goes bad in any finally block. Commented Apr 21, 2015 at 18:13
  • 1
    That's true, but one can (and generally should) guard finally blocks against exceptions that one can realistically expect to occur in such a way that the original and new exceptions both get logged. Unfortunately, doing that will often require memory allocation, which could cause failures of its own. Commented Apr 21, 2015 at 18:33