Skip to content

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Aug 31, 2025

The process can often have enough memory to print verbose exception message when OutOfMemoryException is thrown. Try to print the verbose exception message for OutOfMemoryException first, and fallback to short message without any details only if that fails.

The process can often have enough memory to print verbose exception
message when OutOfMemoryException is thrown. Try to print the verbose
exception message for OutOfMemoryException first, and fallback to short
message without any details only if that fails.
@Copilot Copilot AI review requested due to automatic review settings August 31, 2025 22:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the exception handling logic in the CoreCLR to improve OutOfMemoryException reporting. The change removes the special case handling that prevented verbose exception messages for OutOfMemoryException and instead attempts to print detailed exception information first, falling back to a short message only if printing the verbose message fails.

Key changes:

  • Removed early detection and special handling of OutOfMemoryException
  • Simplified the stack overflow check logic
  • Added exception handling to catch failures when printing verbose messages and provide a fallback for OutOfMemoryException
Comments suppressed due to low confidence (1)

src/coreclr/vm/excep.cpp:1

  • The error handling logic is inconsistent. For OutOfMemoryException, only a message is printed, but for other exceptions, additional logging and event log operations are performed. This creates different error reporting behaviors that could make debugging more difficult. Consider providing consistent error handling for all exception types in the catch block.
// Licensed to the .NET Foundation under one or more agreements.

@jkotas
Copy link
Member Author

jkotas commented Aug 31, 2025

Example:

GC.KeepAlive(new int[Int32.MaxValue]);

Before this change

Out of memory.

After this change:

Unhandled exception. System.OutOfMemoryException: Array dimensions exceeded supported range.
   at Program.<Main>$(String[] args)

@jkotas jkotas requested a review from janvorli August 31, 2025 22:27
Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@jkotas jkotas merged commit f1cbe0f into dotnet:main Sep 1, 2025
97 of 99 checks passed
@jkotas jkotas deleted the oom-message branch September 8, 2025 17:32
@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants