[system.xml] Add more invalid argument checks
authorMarek Safar <marek.safar@gmail.com>
Tue, 11 Feb 2014 10:34:21 +0000 (11:34 +0100)
committerMarek Safar <marek.safar@gmail.com>
Tue, 11 Feb 2014 15:50:13 +0000 (16:50 +0100)
mcs/class/System.XML/System.Xml/XmlReader.cs

index 66f78e5f37a2979242d54706282df2f8c68d7d0f..bb8030264e0872e94f09e941af5669a43f702e91 100644 (file)
@@ -1006,7 +1006,11 @@ namespace System.Xml
 #if NET_4_5
                public virtual DateTimeOffset ReadContentAsDateTimeOffset ()
                {
-                       return XmlConvert.ToDateTimeOffset (ReadContentString ());
+                       try {
+                               return XmlConvert.ToDateTimeOffset (ReadContentString ());
+                       } catch (Exception e) {
+                               throw XmlError ("Typed value is invalid.", e);
+                       }
                }
 #endif
 
@@ -1022,6 +1026,11 @@ namespace System.Xml
 
                public virtual object ReadElementContentAs (Type returnType, IXmlNamespaceResolver namespaceResolver, string localName, string namespaceURI)
                {
+                       if (localName == null)
+                               throw new ArgumentNullException ("localName");
+                       if (namespaceURI == null)
+                               throw new ArgumentNullException ("namespaceURI");
+
                        bool isEmpty = IsEmptyElement;
                        ReadStartElement (localName, namespaceURI);
                        if (isEmpty)
@@ -1096,7 +1105,7 @@ namespace System.Xml
                        } catch (Exception ex) {
                                throw XmlError (String.Format ("Current text value '{0}' is not acceptable for specified type '{1}'. {2}", text, type, ex != null ? ex.Message : String.Empty), ex);
                        }
-                       throw new ArgumentException (String.Format ("Specified type '{0}' is not supported.", type));
+                       throw new XmlException (String.Format ("Specified type '{0}' is not supported.", type));
                }
 
                public virtual bool ReadElementContentAsBoolean ()