[longomatch] Fix exception parsing colors



commit 3b25a03ccee298bef0ed1286f51a8d48bdd64f17
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Feb 27 13:32:51 2015 +0100

    Fix exception parsing colors

 LongoMatch.Core/Common/Color.cs |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/LongoMatch.Core/Common/Color.cs b/LongoMatch.Core/Common/Color.cs
index 7c1e0e4..0aeb4ad 100644
--- a/LongoMatch.Core/Common/Color.cs
+++ b/LongoMatch.Core/Common/Color.cs
@@ -91,7 +91,7 @@ namespace LongoMatch.Core.Common
 
                static public Color Parse (string colorHex)
                {
-                       byte r, g, b, a=Byte.MaxValue;
+                       byte r, g, b, a = Byte.MaxValue;
                        
                        if (!colorHex.StartsWith ("#")) {
                                return null;
@@ -99,11 +99,17 @@ namespace LongoMatch.Core.Common
                        if (colorHex.Length != 7 && colorHex.Length != 9) {
                                return null;
                        }
-                       r = Byte.Parse (colorHex.Substring (1, 2), NumberStyles.HexNumber);
-                       g = Byte.Parse (colorHex.Substring (3, 2), NumberStyles.HexNumber);
-                       b = Byte.Parse (colorHex.Substring (5, 2), NumberStyles.HexNumber);
-                       if (colorHex.Length == 9) {
-                               a = Byte.Parse (colorHex.Substring (7, 2), NumberStyles.HexNumber);
+                       
+                       try {
+                               r = Byte.Parse (colorHex.Substring (1, 2), NumberStyles.HexNumber);
+                               g = Byte.Parse (colorHex.Substring (3, 2), NumberStyles.HexNumber);
+                               b = Byte.Parse (colorHex.Substring (5, 2), NumberStyles.HexNumber);
+                               if (colorHex.Length == 9) {
+                                       a = Byte.Parse (colorHex.Substring (7, 2), NumberStyles.HexNumber);
+                               }
+                       } catch (FormatException ex) {
+                               Log.Exception (ex);
+                               return null;
                        }
                        return new Color (r, g, b, a);
                }


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