Datasheet
error condition (for example, a file not being found, or being denied permission to perform some opera-
tion). These conditions can be defined as narrowly or as widely as you want. The exception architecture
ensures that when an error condition occurs, execution can immediately jump to the exception handler
routine that is most specifically geared to handle the exception condition in question.
The architecture of exception handling also provides a convenient means to pass an object containing
precise details of the exception condition to an exception handling routine. This object might include
an appropriate message for the user and details of exactly where in the code the exception was
detected.
Most exception-handling architecture, including the control of program flow when an exception occurs,
is handled by the high-level languages (C#, Visual Basic 2005, C++), and is not supported by any special
IL commands. C#, for example, handles exceptions using
try{}, catch{}, and finally{} blocks of
code. (For more details, see Chapter 13.)
What .NET does do, however, is provide the infrastructure to allow compilers that target .NET to support
exception handling. In particular, it provides a set of .NET classes that can represent the exceptions, and
the language interoperability to allow the thrown exception objects to be interpreted by the exception-
handling code, irrespective of what language the exception-handling code is written in. This language
independence is absent from both the C++ and Java implementations of exception handling, although it
is present to a limited extent in the COM mechanism for handling errors, which involves returning error
codes from methods and passing error objects around. The fact that exceptions are handled consistently
in different languages is a crucial aspect of facilitating multilanguage development.
Use of Attributes
Attributes are a feature that is familiar to developers who use C++ to write COM components (through
their use in Microsoft’s COM Interface Definition Language [IDL]). The initial idea of an attribute was that
it provided extra information concerning some item in the program that could be used by the compiler.
Attributes are supported in .NET — and hence now by C++, C#, and Visual Basic 2005. What is, how-
ever, particularly innovative about attributes in .NET is that a mechanism exists whereby you can
define your own custom attributes in your source code. These user-defined attributes will be placed
with the metadata for the corresponding data types or methods. This can be useful for documentation
purposes, where they can be used in conjunction with reflection technology in order to perform pro-
gramming tasks based on attributes. Also, in common with the .NET philosophy of language inde-
pendence, attributes can be defined in source code in one language and read by code that is written in
another language.
Attributes are covered in Chapter 12, “Reflection.”
Assemblies
An assembly is the logical unit that contains compiled code targeted at the .NET Framework. Assemblies
are not covered in great detail in this chapter because they are covered in detail in Chapter 16,
“Assemblies,” but we summarize the main points here.
17
Chapter 1: .NET Architecture
24727c01.qxd:WroxPro 5/7/07 12:12 PM Page 17