[hyena] Log: deprecate Exception() methods



commit 8433ac4d3dc4b5d5892712338734314bffee5573
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Thu Jul 17 12:34:48 2014 +0200

    Log: deprecate Exception() methods
    
    As a follow-up to this improvement [1], it's actually better
    to require the caller to be explicit about if she considers
    the exception to be an error or a warning, so let's deprecate
    the methods Exception(e) and Exception(msg,e) entirely and
    recommend new overloads for Error() and Warning() that can
    receive an Exception parameter.
    
    The motivation for this is that I keep seeing many banshee
    contributors use the Error() methods along with a message
    simply extracted from the exception via 'ex.Message'. This,
    in most cases, is unacceptable because it doesn't log the
    stacktrace of the exception and doesn't aid debugging.
    
    [1] https://git.gnome.org/browse/hyena/commit/?id=3feafb7328154b3c4901e8e57b70b05d9b4c9105

 Hyena/Hyena/Log.cs |   34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/Hyena/Hyena/Log.cs b/Hyena/Hyena/Log.cs
index 814d773..ebe25b0 100644
--- a/Hyena/Hyena/Log.cs
+++ b/Hyena/Hyena/Log.cs
@@ -339,7 +339,7 @@ namespace Hyena
 
         public static void Warning (string message)
         {
-            Warning (message, null);
+            Warning (message, (string)null);
         }
 
         public static void Warning (string message, string details)
@@ -352,6 +352,16 @@ namespace Hyena
             Commit (LogEntryType.Warning, message, details, showUser);
         }
 
+        public static void Warning (Exception e)
+        {
+            ExceptionImpl (null, e, false);
+        }
+
+        public static void Warning (string message, Exception e)
+        {
+            ExceptionImpl (message, e, false);
+        }
+
         public static void Warning (string message, bool showUser)
         {
             Warning (message, null, showUser);
@@ -368,7 +378,7 @@ namespace Hyena
 
         public static void Error (string message)
         {
-            Error (message, null);
+            Error (message, (string)null);
         }
 
         public static void Error (string message, string details)
@@ -386,6 +396,16 @@ namespace Hyena
             Error (message, null, showUser);
         }
 
+        public static void Error (Exception e)
+        {
+            ExceptionImpl (null, e, true);
+        }
+
+        public static void Error (string message, Exception e)
+        {
+            ExceptionImpl (message, e, true);
+        }
+
         public static void ErrorFormat (string format, params object [] args)
         {
             Error (String.Format (format, args));
@@ -402,13 +422,21 @@ namespace Hyena
             }
         }
 
+        [Obsolete ("Use Error(ex) or Warning(ex)")]
         public static void Exception (Exception e)
         {
             Exception (null, e);
         }
 
+        [Obsolete ("Use Error(msg,ex) or Warning(msg,ex)")]
         public static void Exception (string message, Exception e)
         {
+            bool severe = String.IsNullOrEmpty (message);
+            ExceptionImpl (message, e, severe);
+        }
+
+        private static void ExceptionImpl (string message, Exception e, bool severe)
+        {
             Stack<Exception> exception_chain = new Stack<Exception> ();
             StringBuilder builder = new StringBuilder ();
 
@@ -426,7 +454,7 @@ namespace Hyena
                 }
             }
 
-            if (message != null) {
+            if (!severe) {
                 Log.Warning (message, builder.ToString (), false);
             } else {
                 Log.Error ("Caught an exception", builder.ToString (), false);


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