Free mag vol1 | Page 339

CHAPTER 7  UNDERSTANDING STRUCTURED EXCEPTION HANDLING Who Is Throwing What? Given that a method in the .NET Framework could throw any number of exceptions under various circumstances, a logical question is, “How do I know which exceptions may be thrown by a given base class library method?” The ultimate answer is simple: consult the .NET Framework 4.5 SDK documentation. Each method in the help system documents the exceptions a given member may throw. As a quick alternative, Visual Studio allows you to view the list of all exceptions thrown by a base class library member (if any) simply by hovering your mouse cursor over the member name in the code window (see Figure 7-2). Figure 7-2. Identifying the exceptions thrown from a given method  Note For those coming to .NET from a Java background, understand that type members are not prototyped with the set of exceptions they may throw (in other words, .NET does not support checked exceptions). For better or for worse, you are not required to handle each and every exception thrown from a given member. The Result of Unhandled Exceptions At this point, you might be wondering what would happen if you do not handle an exception thrown in your direction. Assume that the logic in Main() increases the speed of the Car object beyond the maximum speed, without the benefit of try/catch logic: 277