Chapter 2: Types and Exceptions

Chapter 2

Types and Exceptions

Before you begin drilling down into the Microsoft .NET Framework class library (FCL) and the various programming models that it supports, it s helpful to understand what the FCL is made of. The FCL is a library of types, which is a generic way of referring to classes, structs, interfaces, enumerations, and delegates. This chapter defines these terms and will make Chapter 3 more meaningful to developers who are new to the .NET Framework. This chapter also introduces some potential pitfalls related to types, including common errors that arise when using types that encapsulate file handles and other resources that aren t managed by the garbage collector.

Understanding the .NET Framework s type system and the differences between the various kinds of data types that it supports is important, but so is understanding how types are loaded, versioned, and deployed. Types are packaged in assemblies. The FCL is a set of many different assemblies, each one of them shared so that any application can use it. Applications, too, are deployed as assemblies. You already know that an assembly is a group of one or more files. You even created a single-file assembly (Hello.exe) in Chapter 1. What you don t know yet is how to create assemblies of your own that contain types that can be used by other programs. You ll remedy that in this chapter by building and deploying a multifile, multilanguage assembly, and then building a client that dynamically links to it. In addition to gaining valuable insight into how the FCL works, you ll see what it takes to build class libraries of your own and learn how to use the assembly-based versioning mechanism in the common language runtime (CLR) to avoid DLL Hell the term used to describe what happens when a fix made to a DLL for the benefit of one application breaks another application (or perhaps breaks the very application that the fix was intended to help).

Finally, you ll learn about exception handling. Applications that use the .NET Framework employ a C++-like try/catch mechanism to achieve robustness without having to check the return value from each and every method call. In fact, checking return values does little good because the CLR and FCL don t flag errors by returning error codes; they throw exceptions. A working knowledge of how exception handling works and how languages such as C# expose the CLR s exception handling mechanism is essential to becoming a proficient .NET Framework programmer.



Programming Microsoft  .NET
Applied MicrosoftNET Framework Programming in Microsoft Visual BasicNET
ISBN: B000MUD834
EAN: N/A
Year: 2002
Pages: 101

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net