Improved debugging messages
authorStefanos A. <stapostol@gmail.com>
Wed, 2 Oct 2013 15:55:57 +0000 (17:55 +0200)
committerStefanos A. <stapostol@gmail.com>
Wed, 2 Oct 2013 15:55:57 +0000 (17:55 +0200)
Exceptions that occur in the example process are now logged.

Source/Examples/Main.cs

index 087382b4944a00cfbe09e0a529a270be677f990e..89d03fdceefd2640a71668ab09c6dedd81cc13c4 100644 (file)
@@ -46,12 +46,33 @@ namespace Examples
                 Trace.Listeners.Add(dbg);
                 Trace.Listeners.Add(new ConsoleTraceListener());
 
-                var example = Type.GetType(type);
-                if (example != null)
+                try
+                {
+                    if (File.Exists("debug.log"))
+                        File.Delete("debug.log");
+                    if (File.Exists("trace.log"))
+                        File.Delete("trace.log");
+                }
+                catch (Exception e)
+                {
+                    Trace.WriteLine(String.Format("Could not access debug.log", e.ToString()));
+                }
+
+                try
+                {
+                    var example = Type.GetType(type);
+                    if (example != null)
+                    {
+                        example.InvokeMember("Main",
+                            BindingFlags.InvokeMethod | BindingFlags.Static |
+                            BindingFlags.Public | BindingFlags.NonPublic,
+                            null, null, null);
+                    }
+                }
+                catch (Exception e)
                 {
-                    example.InvokeMember("Main",
-                        BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic,
-                        null, null, null);
+                    Trace.WriteLine(String.Format("Exception occured in example {0}: {1}",
+                        type, e.ToString()));
                 }
 
                 dbg.Flush();
@@ -75,18 +96,6 @@ namespace Examples
 
                     using (Form browser = new ExampleBrowser())
                     {
-                        try
-                        {
-                            if (File.Exists("debug.log"))
-                                File.Delete("debug.log");
-                            if (File.Exists("trace.log"))
-                                File.Delete("trace.log");
-                        }
-                        catch (Exception expt)
-                        {
-                            MessageBox.Show("Could not access debug.log", expt.ToString());
-                        }
-
                         Application.Run(browser);
                     }
                 }