简体   繁体   中英

Why do some .NET BCL methods not throw exceptions?

For example neither the BitConverter.GetBytes Method (Int64) nor XmlUrlResolver Constructor are not documented as throwing exceptions. Are they indicating an error by using a return value ?

Methods do not need to throw exceptions if their logic cannot give rise to any errors. This is obvious in the case of BitConverter.GetBytes ; the conversion is guaranteed to succeed for any Int64 value.

There are some catastrophic exceptions that may be thrown by any method, such as OutOfMemoryException or StackOverflowException .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM