Ignore:
Timestamp:
Jul 12, 2006, 10:09:57 PM (18 years ago)
Author:
mayuki
Message:

ハンドルされていない例外をハンドルしてスタックトレースを保存する機能をつけた

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MacFaceFloat/MacFaceApp.cs

    r73 r75  
    4444                public static void Main(string[] args)
    4545                {
     46                        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    4647                        MacFaceApp app = new MacFaceApp();
    4748                        app.StartApplication();
     
    403404                        window.Show();
    404405                }
     406
     407                /// <summary>
     408                /// ƒnƒ“ƒhƒ‹‚³‚ê‚Ä‚¢‚È‚¢—áŠO‚ðƒLƒƒƒbƒ`‚µ‚āAƒXƒ^ƒbƒNƒgƒŒ[ƒX‚ð•Û‘¶‚µ‚ăfƒoƒbƒO‚ɖ𗧂Ăé
     409                /// </summary>
     410                /// <param name="sender"></param>
     411                /// <param name="e"></param>
     412                private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
     413                {
     414                        Exception ex = e.ExceptionObject as Exception; // Exception ˆÈŠO‚ª”ò‚ñ‚Å‚­‚é‚Ì‚Í’´“ÁŽê‚ȏꍇ‚̂݁B
     415
     416                        if (MessageBox.Show(
     417                                String.Format("ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚ÌŽÀs’†‚É—\Šú‚µ‚È‚¢d‘å‚ȃGƒ‰[‚ª”­¶‚µ‚Ü‚µ‚½B\n\nƒGƒ‰[“à—e:\n{0}\n\nƒGƒ‰[î•ñ‚ðƒtƒ@ƒCƒ‹‚É•Û‘¶‚µA•ñ‚µ‚Ä‚¢‚½‚¾‚­‚±‚Æ‚Å•s‹ï‡‚Ì‰ðŒˆ‚É–ð—§‚Â‰Â”\«‚ª‚ ‚è‚Ü‚·BƒGƒ‰[î•ñ‚ðƒtƒ@ƒCƒ‹‚É•Û‘¶‚µ‚Ü‚·‚©?",
     418                                ((Exception)(e.ExceptionObject)).Message)
     419                                , Application.ProductName
     420                                , MessageBoxButtons.YesNo
     421                                , MessageBoxIcon.Error
     422                                , MessageBoxDefaultButton.Button1
     423                                ) == DialogResult.Yes)
     424                        {
     425                                using (SaveFileDialog saveFileDialog = new SaveFileDialog())
     426                                {
     427                                        saveFileDialog.DefaultExt = "txt";
     428                                        saveFileDialog.Filter = "ƒeƒLƒXƒgƒtƒ@ƒCƒ‹|*.txt";
     429                                        saveFileDialog.FileName = String.Format("macface4win_stacktrace_{0:yyyyMMdd_HHmmss}.txt", DateTime.Now);
     430                                        if (saveFileDialog.ShowDialog() == DialogResult.OK)
     431                                        {
     432                                                using (Stream stream = saveFileDialog.OpenFile())
     433                                                using (StreamWriter sw = new StreamWriter(stream))
     434                                                {
     435                                                        sw.WriteLine("”­¶Žž: {0}", DateTime.Now);
     436                                                        sw.WriteLine();
     437                                                        sw.WriteLine("MacFace for Windows:");
     438                                                        sw.WriteLine("========================");
     439                                                        sw.WriteLine("ƒo[ƒWƒ‡ƒ“: {0}", Application.ProductVersion);
     440                                                        sw.WriteLine("ƒAƒZƒ“ƒuƒŠ: {0}", Assembly.GetExecutingAssembly().FullName);
     441                                                        sw.WriteLine();
     442                                                        sw.WriteLine("ŠÂ‹«î•ñ:");
     443                                                        sw.WriteLine("========================");
     444                                                        sw.WriteLine("ƒIƒyƒŒ[ƒeƒBƒ“ƒOƒVƒXƒeƒ€: {0}", Environment.OSVersion);
     445                                                        sw.WriteLine("Microsoft .NET Framework: {0}", Environment.Version);
     446                                                        sw.WriteLine();
     447                                                        sw.WriteLine("ƒnƒ“ƒhƒ‹‚³‚ê‚Ä‚¢‚È‚¢—áŠO: ");
     448                                                        sw.WriteLine("=========================");
     449                                                        sw.WriteLine(ex.ToString());
     450                                                }
     451                                        }
     452                                }
     453                               
     454                        }
     455                }
    405456        }
    406457}
Note: See TracChangeset for help on using the changeset viewer.