Add try-catch
authorVance Morrison <vancemorrison@comcast.net>
Mon, 30 Jul 2018 22:02:17 +0000 (15:02 -0700)
committerVance Morrison <vancemorrison@comcast.net>
Mon, 30 Jul 2018 22:02:17 +0000 (15:02 -0700)
src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs

index 0e7780b..ee2bc88 100644 (file)
@@ -5461,25 +5461,30 @@ namespace System.Diagnostics.Tracing
                     foreach (FieldInfo staticField in staticFields)
                     {
                         object constantValObj = staticField.GetRawConstantValue();
+
                         if (constantValObj != null)
                         {
-                            long hexValue = Convert.ToInt64(constantValObj); // Handles all integer types.  
+                            try
+                            {
+                                long hexValue = hexValue = Convert.ToInt64(constantValObj); // Handles all integer types.
 
-                            // ETW requires all bitmap values to be powers of 2.  Skip the ones that are not. 
-                            // TODO: Warn people about the dropping of values. 
-                            if (isbitmap && ((hexValue & (hexValue - 1)) != 0 || hexValue == 0))
-                                continue;
+                                // ETW requires all bitmap values to be powers of 2.  Skip the ones that are not. 
+                                // TODO: Warn people about the dropping of values. 
+                                if (isbitmap && ((hexValue & (hexValue - 1)) != 0 || hexValue == 0))
+                                    continue;
 
-                            // We have a valid value, write the header if we have not already.  
-                            if (!headerWriten)
-                            {
-                                sb.Append("  <").Append(mapKind).Append(" name=\"").Append(enumType.Name).Append("\">").AppendLine();
-                                headerWriten = true;
-                            }
+                                // We have a valid value, write the header if we have not already.  
+                                if (!headerWriten)
+                                {
+                                    sb.Append("  <").Append(mapKind).Append(" name=\"").Append(enumType.Name).Append("\">").AppendLine();
+                                    headerWriten = true;
+                                }
 
-                            sb.Append("   <map value=\"0x").Append(hexValue.ToString("x", CultureInfo.InvariantCulture)).Append("\"");
-                            WriteMessageAttrib(sb, "map", enumType.Name + "." + staticField.Name, staticField.Name);
-                            sb.Append("/>").AppendLine();
+                                sb.Append("   <map value=\"0x").Append(hexValue.ToString("x", CultureInfo.InvariantCulture)).Append("\"");
+                                WriteMessageAttrib(sb, "map", enumType.Name + "." + staticField.Name, staticField.Name);
+                                sb.Append("/>").AppendLine();
+                            }
+                            catch { }  
                         }
                     }