From 894df04823d9daa845d542aaaa5216a3b949fc21 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Tue, 8 Sep 2009 02:01:54 +0000 Subject: Allow exceptions to go to the console svn path=/trunk/mono-tools/; revision=141480 --- gsharp/Main.cs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/gsharp/Main.cs b/gsharp/Main.cs index 2dc86749..06f1dd2f 100644 --- a/gsharp/Main.cs +++ b/gsharp/Main.cs @@ -10,6 +10,7 @@ using System.Diagnostics; using System.Reflection; using Mono.Options; using System.Collections.Generic; +using System.IO; namespace Mono.CSharp.Gui { @@ -25,6 +26,14 @@ namespace Mono.CSharp.Gui p.WriteOptionDescriptions (Console.Out); } + + static void ResetOutput () + { + var stdout = new StreamWriter (Console.OpenStandardOutput ()) { AutoFlush = true }; + var stderr = new StreamWriter (Console.OpenStandardError ()) { AutoFlush = true }; + Console.SetOut (stdout); + Console.SetError (stderr); + } public static void Main (string[] args) { @@ -122,22 +131,15 @@ namespace Mono.CSharp.Gui m.ShowAll (); if (!HostHasGtkRunning){ - System.IO.TextWriter cout = Console.Out; - System.IO.TextWriter cerr = Console.Error; - try { GLib.ExceptionManager.UnhandledException += delegate (GLib.UnhandledExceptionArgs a) { - Console.SetOut (cout); - Console.SetError (cerr); - + ResetOutput (); Console.WriteLine ("Application terminating: " + a.ExceptionObject); }; Application.Run (); - } catch (Exception) { - Console.SetOut (cout); - Console.SetError (cerr); - + } catch (Exception e) { + ResetOutput (); throw; } } -- cgit v1.2.3