質問

私はperiodicalyサーバー上で起動された単一のAppDomainで簡単なアプリケーションを持っています。時には、未処理の例外が中止/再試行/アップダイアログポップを無視aplication、デフォルトで発生します。私は何とかstrerrは上の例外を示すと単に出力からedialogを防ぎ、アプリケーションを終了する必要があります。だから私は、try-catchステートメントで、メインメソッドですべてのコードを囲むが、それは全く役に立ちませんでした - 例外ダイアログがまだ時々示されている。

メイン()のコードは次のようになります:

try
{
    RunApplication();
}
catch (Exception exc)
{   
    Console.Error.WriteLine(exc.ToString());
    Console.Error.WriteLine(exc.StackTrace);
    if (exc.InnerException != null)
    {
       Console.Error.WriteLine(exc.InnerException.ToString());
       Console.Error.WriteLine(exc.InnerException.StackTrace);
    }
    Environment.Exit(666);
}

こののtry-catch句は、すべての未処理の例外をキャッチshoudと例外ダイアログでは、私の知る限りをポップアップすることはありません。私何か不足していますか?または例外ダイアログ/アプリケーション・エラー・コードに関連するいくつかの特殊な動作を制御するサーバ上の任意の設定(レジストリなど)はありますか?

役に立ちましたか?

解決

あなたがアプリケーションドメインにに加入することができます未処理の例外イベントがあります。

    public static void Main()   
    {   
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);

        //some code here....
    }   

    /// <summary>
    /// Occurs when you have an unhandled exception
    /// </summary>
    public static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)   
    { 
        //here's how you get the exception  
        Exception exception = (Exception)e.ExceptionObject;  

        //bail out in a tidy way and perform your logging
    }

他のヒント

は、あなたのcatch節が例外をスローすることができるという可能性を考慮していますか? あなたがメインのアプリでスレッドを生成しますか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top