- PR -

ハンドルされていない例外

1
投稿者投稿内容
いっこさん
ベテラン
会議室デビュー日: 2003/07/03
投稿数: 67
投稿日時: 2004-09-10 10:51
こんにちわ。いつも参考&勉強させて頂いています。

コンソールアプリケーションで「ハンドルされていない例外」を処理したいと思っています。
Google等で調べたところUnhandledExceptionというのがありました。
MSDNに掲載されているサンプルコードを実行したところ、UnhandledExceptionをハンドルした処理より先に「システムの既定のハンドラ(というのでしょうか?)」が先に処理されます。
「システムの既定のハンドラ」に処理させない為に、UnhandledExceptionを使用したいのですが、そのようなことは不可能なのでしょうか?

アドバイス・ご指摘等ありましたらご教示お願いします。

OS:Win XP SP1
言語:VB.NET 2003
コード:
Module Module1
    Sub Main()
        Dim currentDomain As AppDomain = AppDomain.CurrentDomain
        AddHandler currentDomain.UnhandledException, AddressOf MyHandler

        Try
            Throw New Exception("1")
        Catch e As Exception
            Console.WriteLine("Catch clause caught : " + e.Message)
        End Try

        Throw New Exception("2")

        ' Output:
        '   Catch clause caught : 1
        '   MyHandler caught : 2
    End Sub 'Main


    Sub MyHandler(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs)
        Dim e As Exception = DirectCast(args.ExceptionObject, Exception)
        Console.WriteLine("MyHandler caught : " + e.Message)
    End Sub 'MyUnhandledExceptionEventHandler
End Module



#コードまんまですね…
1

スキルアップ/キャリアアップ(JOB@IT)