[smuxi/experiments/configurable_message_patterns: 4/6] Frontend: handle exceptions thrown by commands



commit 8aebf01f52208100608fa36a4ad7822a9ca1d7b8
Author: Mirco Bauer <meebey meebey net>
Date:   Sun Feb 16 18:47:55 2014 +0100

    Frontend: handle exceptions thrown by commands
    
    Letting the frontend crash because a command failed is a bit too harsh.

 src/Frontend/CommandManager.cs |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/src/Frontend/CommandManager.cs b/src/Frontend/CommandManager.cs
index b8c445c..9bf7306 100644
--- a/src/Frontend/CommandManager.cs
+++ b/src/Frontend/CommandManager.cs
@@ -115,7 +115,18 @@ namespace Smuxi.Frontend
             }
 
             f_TaskQueue.Queue(delegate {
-                DoExecute(cmd);
+                try {
+                    DoExecute(cmd);
+                } catch (Exception ex) {
+#if LOG4NET
+                    f_Logger.Error("Execute(): DoExecute() threw exception!", ex);
+#endif
+                    var msg = new MessageBuilder().
+                        AppendErrorText("Command '{0}' failed. Reason: {1}",
+                                        cmd.Command, ex.Message).
+                        ToMessage();
+                    AddMessageToFrontend(cmd, msg);
+                }
             });
         }
 
@@ -134,6 +145,8 @@ namespace Smuxi.Frontend
                         CommandEcho(cmd);
                         handled = true;
                         break;
+                    case "exception":
+                        throw new Exception("You asked for it.");
                 }
             }
             if (handled) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]