Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Catching unhandled exceptions

  • Loading branch information...
commit 7db7370d8ae30ee3559d2e89bd95fcd8531d623c 1 parent d4493a0
@codereflection authored
Showing with 19 additions and 5 deletions.
  1. +19 −5 src/Giles/Program.cs
View
24 src/Giles/Program.cs
@@ -26,6 +26,8 @@ static void Main(string[] args)
Console.WriteLine(GetGilesFunnyLine());
+ AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
+
var parser = new CommandLineParser(
new CommandLineParserSettings(false, Console.Error));
@@ -50,6 +52,11 @@ static void Main(string[] args)
MainFeedbackLoop();
}
+ static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+ {
+ Console.WriteLine("Critical Error: {0}\nTerminating: {1}", e.ExceptionObject, e.IsTerminating);
+ }
+
static GilesConfig GetGilesConfigFor(CLOptions options)
{
var solutionPath = options.SolutionPath.Replace("\"", string.Empty);
@@ -147,11 +154,18 @@ static void MainFeedbackLoop()
{
while (!quitRequested)
{
- var keyValue = Console.ReadKey(true).KeyChar.ToString().ToLower();
-
- menuOptions
- .Where(option => option.HandlesKey(keyValue))
- .Each(option => option.Task());
+ try
+ {
+ var keyValue = Console.ReadKey(true).KeyChar.ToString().ToLower();
+
+ menuOptions
+ .Where(option => option.HandlesKey(keyValue))
+ .Each(option => option.Task());
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Error: {0}", e);
+ }
}
Console.WriteLine("Until next time...");
}
Please sign in to comment.
Something went wrong with that request. Please try again.