다음을 통해 공유


System.Drawing OutOfMemoryException이 ExternalException으로 변경됨

System.Drawing의 GDI+ 오류 처리가 ExternalException 오류에 대해 이전 OutOfMemoryException이 아닌 Status.OutOfMemory을 throw하도록 업데이트되었습니다.

도입된 버전

.NET 10

이전 동작

이전에 GDI+가 Status.OutOfMemory 오류를 만났을 때(이는 실제 메모리 문제가 아닌 잘못된 입력으로 인해 자주 발생), System.Drawing API가 예외 OutOfMemoryException을(를) 던졌습니다.

새 동작

.NET 10부터 GDI+에서 Status.OutOfMemory 오류가 발생하면 System.Drawing API가 ExternalException을(를) 던집니다.

파괴적 변경 유형

이것은 동작 변경입니다.

변경 이유

GDI+는 내부 개체를 만들 수 없는 경우 오류를 반환하는 데 특히 적합하지 않습니다. 잘못된 입력으로 인해 개체를 만들지 못하는 경우가 많으며 상위 수준 코드는 null을 가져오고 이를 으로 Status.OutOfMemory바꿉니다. 오류가 실제 메모리 문제와 관련이 없는 경우가 많으므로 이는 종종 혼동의 원인입니다.

이 변경은 ExternalException로, 이 예외 유형이 유사한 GDI+ 오류에 대해 다른 System.Drawing 코드 경로에서도 이미 throw되고 있어 보다 정확한 오류 보고를 제공합니다.

System.Drawing API를 사용할 때, 코드가 OutOfMemoryException를 catch하는 경우 이러한 GDI+ 오류를 처리하기 위해 ExternalException도 catch해야 합니다.

try
{
    // System.Drawing operations
}
catch (ExternalException ex)
{
    // Handle GDI+ errors (including former OutOfMemoryException cases)
}
catch (OutOfMemoryException ex)
{
    // Handle actual memory issues
}
Try
    ' System.Drawing operations
Catch ex As ExternalException
    ' Handle GDI+ errors (including former OutOfMemoryException cases)
Catch ex As OutOfMemoryException
    ' Handle actual memory issues
End Try

영향을 받는 API

GDI+와 상호 작용하고 이전에 OutOfMemoryException 오류에 대해 Status.OutOfMemory 예외를 발생시킬 수 있었던 모든 System.Drawing API에는 다음이 포함되지만 이에 국한되지 않습니다: