Partilhar via


Handling SMO Exceptions

In managed code, exceptions are thrown when an error occurs. SMO methods and properties do not report success or failure in the return value. Instead, exceptions can be caught and handled by an exception handler.

Different exception classes exist in the SMO. Information about the exception can be extracted from the exception properties such as the Message property that gives a text message about the exception.

The exception handling statements are specific to the programming language. For example, in Microsoft Visual Basic it is the Catch statement.

Inner Exceptions

Exceptions can either be general or specific. General exceptions contain a set of specific exceptions. Several Catch statements can be used to handle anticipated errors and let remaining errors fall through to general exception handling code. Exceptions often occur in a cascading sequence. Frequently, an SMO exception might have been caused by an SQL exception. The way to detect this is to use the InnerException property successively to determine the original exception that caused the final, top-level exception.

Note

The SQLException exception is declared in the System.Data.SqlClient namespace.

A diagram that shows the levels from which an excp

The diagram shows the flow of exceptions through the layers of the application.

See Also

Tasks

How to: Catch an Exception in Visual Basic .NET

Help and Information

Getting SQL Server 2005 Assistance