835

баги в FCL

информация к размышлениюя и раньше сталкивался с разными багами, но большей частью у компонент VS2003 что в обще не так страшно, потмуо что в следующей версии их наверное уж не будет. Но оказывается написании самого FCL микрософт не следовал порой собственным же указаниям о том как следует писать библиотеки. Вот выдержка из книги уважаемого J.Richer:In this chapter, I’ve given you my recommendations for working with exceptions. Theserecommendations are based on conversations with many developers and my own experiencewriting code for many years. In the previous section, I mentioned that many of the FCL exceptiontypes are missing a constructor that allows the inner exception to be set. This is just one type of bugin the FCL. Unfortunately, the FCL contains many more bugs related to exception handling. In thissection, my intent is to make you aware of these bugs so that you won’t waste as much time as Ihave trying to figure out what’s going on when your code doesn’t work quite as you expect.Microsoft hasn’t followed a lot of the guidelines that I describe in this chapter. In fact, quite a bit ofMicrosoft’s code violates Microsoft’s own guidelines, a situation that can make working with the FCLdifficult at times. The problem is exacerbated by the fact that the FCL documentation doesn’t alwaysdescribe what exceptions a developer can expect or how to recover from them.The first problem is that Microsoft’s FCL code is peppered with the following constructs:catch { ... }catch (Exception) { ... }catch (ApplicationException) { ... }As I explained previously, these constructs catch and swallow exceptions that shouldn’t be caughtand swallowed by a class library.Here’s an example: the System.IO.Directory and System.IO.File types have static Existsmethods. Both methods return true or false depending on whether the path argument identifies adirectory/file that exists on the user’s disk drive. If anything goes wrong inside these methods, themethods catch Exception and return false to their caller. The caller has no way to tell whether theexception occurred because the file doesn’t exist or whether the caller doesn’t have sufficientaccess to the directory or file. Also, if a StackOverflowException or an OutOfMemoryExceptionis thrown, then false is also returned!очень интересно и познавательно...
0