2

アンマネージド GDI+ 機能を使用する C# アプリがあり、(アンマネージド?) 例外が発生します。

Log Name: Application
Source: .NET Runtime
Date: 7/1/2013 9:14:58 AM
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: sth
Description:
Application: sth
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException

スタック トレースは次のとおりです。

at System.Drawing.SafeNativeMethods+Gdip.IntGdipDisposeImage(System.Runtime.InteropServices.HandleRef)
at System.Drawing.SafeNativeMethods+Gdip.IntGdipDisposeImage(System.Runtime.InteropServices.HandleRef)
at System.Drawing.Image.Dispose(Boolean)
at System.Drawing.Image.Dispose()
at “..()
at Aspose.Cells.Charts.Chart.ToImage(System.IO.Stream, Aspose.Cells.Rendering.ImageOrPrintOptions)

クラッシュを完全に防ぐことはできますか? 引数なしで catch ステートメントを使用しようとしましたが、sth はそれでは不十分だと言います。これらの欠陥のあるコードで独自の C++ DLL を作成しましたが、DLL が sth をスローしない限り、何も機能していないようです。

__declspec(dllexport) void __cdecl Function1(void) // This doesn't get caught.
{
    char *chrs = new char[1000];
    delete []chrs;
    delete []chrs;
}

__declspec(dllexport) void __cdecl Function3(void) // This doesn't get caught.
{
    try
    {
        MessageBox(NULL, L"AAA", L"Caption", MB_OK);
        char *chrs = NULL;
        chrs[0] = 'a';
    }
    catch(...)
    {
        MessageBox(NULL, L"BBB", L"Caption", MB_OK); // I get no messagebox here... (probably it doesn't get caught)
    }
}

__declspec(dllexport) void __cdecl Function2(void) // This gets caught as a .NET Exception.
{
    throw "Oh My!";
}

では、EXE がクラッシュするのを防ぐために sth を実行できますか?

編集

また、System.AccessViolationExceptionこれはマネージド例外であることを意味しますか? はい、なぜそれをキャッチしないのだろうか... 私のコードは try{}catch(){} 内にラップされています...

EDIT2

私の推測では、GDI+ がヒープを破損し、CLR が後でそれを検出して例外をスローします。ただし、try ブロック内からスローされないため、キャッチできません。この場合、sth を実行できますか?

4

1 に答える 1