--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Net;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Animation;\r
+using System.Windows.Shapes;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+ public partial class App : Application\r
+ {\r
+\r
+ public App()\r
+ {\r
+ this.Startup += this.Application_Startup;\r
+ this.Exit += this.Application_Exit;\r
+ this.UnhandledException += this.Application_UnhandledException;\r
+\r
+ InitializeComponent();\r
+ }\r
+\r
+ private void Application_Startup(object sender, StartupEventArgs e)\r
+ {\r
+ this.RootVisual = new MainPage();\r
+ }\r
+\r
+ private void Application_Exit(object sender, EventArgs e)\r
+ {\r
+\r
+ }\r
+ private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)\r
+ {\r
+ // アプリケーションがデバッガーの外側で実行されている場合、ブラウザーの\r
+ // 例外メカニズムによって例外が報告されます。これにより、IE ではステータス バーに\r
+ // 黄色の通知アイコンが表示され、Firefox にはスクリプト エラーが表示されます。\r
+ if (!System.Diagnostics.Debugger.IsAttached)\r
+ {\r
+\r
+ // メモ : これにより、アプリケーションは例外がスローされた後も実行され続け、例外は\r
+ // ハンドルされません。 \r
+ // 実稼動アプリケーションでは、このエラー処理は、Web サイトにエラーを報告し、\r
+ // アプリケーションを停止させるものに置換される必要があります。\r
+ e.Handled = true;\r
+ Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });\r
+ }\r
+ }\r
+ private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)\r
+ {\r
+ try\r
+ {\r
+ string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;\r
+ errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");\r
+\r
+ System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");\r
+ }\r
+ catch (Exception)\r
+ {\r
+ }\r
+ }\r
+ }\r
+}\r