XmlReader.GetAttribute()不会抛出异常 [英] XmlReader.GetAttribute() doesn't throw an exception
本文介绍了XmlReader.GetAttribute()不会抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果没有找到该属性为什么没有 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.
这篇关于XmlReader.GetAttribute()不会抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文