Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Allow exceptions to go to the console
Browse files Browse the repository at this point in the history
svn path=/trunk/mono-tools/; revision=141480
  • Loading branch information
migueldeicaza committed Sep 8, 2009
1 parent 60b38e0 commit 894df04
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions gsharp/Main.cs
Expand Up @@ -10,6 +10,7 @@
using System.Reflection;
using Mono.Options;
using System.Collections.Generic;
using System.IO;

namespace Mono.CSharp.Gui
{
Expand All @@ -25,6 +26,14 @@ public static void ShowHelp (OptionSet p)

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)
{
Expand Down Expand Up @@ -122,22 +131,15 @@ public static void Start (string title, List<string> files)
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;
}
}
Expand Down

0 comments on commit 894df04

Please sign in to comment.