Handling SMO Exceptions

更新日期: 2006 年 4 月 14 日

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.

ms162127.note(zh-cn,SQL.90).gif注意:
The SQLException exception is declared in the System.Data.SqlClient namespace.

显示级别的关系图

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

请参阅

任务

How to: Catch an Exception in Visual Basic .NET

帮助和信息

获取 SQL Server 2005 帮助