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.
![]() |
---|
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