Databases Reference
In-Depth Information
Error Handling
Errors are a fact of life and a fact of programming. One of the most important aspects of
software development is the ability to process errors and protect users and application
from unwanted behaviors. The ability to understand and handle errors gracefully is espe-
cially important when you are using a complex object model such as AMO, where things
can take an unexpected turn because of network failure. Therefore, we cannot talk about
AMO without talking about error handling.
In this section, we discuss the classes responsible for error handling and show you how to
use those classes. The more often you use them, the less time you will spend debugging
your application.
AMO is built on top of the .NET Framework, so it uses exceptions as error-handling mech-
anisms. When it calls any AMO method or property, an application should be prepared to
get any one of the standard exceptions, such as NotSupportedException , InvalidOperation
Exception , and ArgumentNullException . These exceptions usually indicate a misuse of the
object model—a bug in the code of the client application.
AMO provides a base class for error handling: AmoException (shown in Figure 34.12). It
also provides four classes derived from AmoException , which are designed to allow the
client application to use different error-handling code for different kinds of errors. A client
application that calls AMO objects should be ready to catch an AmoException or, if appro-
priate, the instance of the derived exception class.
System.Exception
AnalysisServices.AmoException
FIGURE 34.12 AMO provides a base class for error handling—AmoException—which is
derived from the System.Exception class.
The following sections discuss the exception classes derived from AmoException .
OperationException
OperationException is thrown when the request sent to the server returns an error or a
warning to the client. Because OperationException is designed to propagate errors and
warnings returned by the server, and because Analysis Services can return multiple
messages for the single request, OperationException contains a collection of XmlaResult
objects. Each XmlaResult object can contain more than one message, so it can have an
XmlaMessageCollection . Each XmlaMessage object is either an error or a warning. AMO
Search WWH ::




Custom Search