XmlReader.GetAttribute()不会抛出异常抛出、异常、XmlReader、GetAttribute

由网友(Tutu颜值担当)分享简介:如果没有找到该属性为什么没有 System.Xml.XmlReader.GetAttribute(字符串)抛出一个异常?这似乎荒唐和危险的一见钟情。Why doesn't System.Xml.XmlReader.GetAttribute(String) throw an exception if the attri...

如果没有找到该属性为什么没有 System.Xml.XmlReader.GetAttribute(字符串)抛出一个异常?这似乎荒唐和危险的一见钟情。

Why doesn't System.Xml.XmlReader.GetAttribute(String) throw an exception if the attribute is not found?! It seems ridiculous and dangerous at first sight.

推荐答案

由于没有什么特殊指出没有找到指定的属性。如果有什么是可选的?那么你会是依靠抛出的异常来控制程序流?

Because there's nothing "exceptional" about not finding a specified attribute. What if it's optional? Would you then be relying on thrown exceptions to control your program flow?

这是不好的做法 - 你应该简单地使用它之前检查null返回值

This isn't good practice - you should simply check the return value for null before using it.

阅读全文

相关推荐

最新文章