The exception that is generated when a warning or error is returned by a database.
System.Object
System.Exception
System.SystemException
System.Runtime.InteropServices.SystemException
System.Data.Common.DbException
IBM.Data.DB2.DB2Exception
[Visual Basic]
<Serializable>
NotInheritable Public Class DB2Exception
Inherits DbException
[C#]
[Serializable]
public sealed class DB2Exception : DbException
[C++]
[Serializable]
public __gc __sealed class DB2Exception : public DbException
[JScript]
public
Serializable
class DB2Exception extends DbException
This class is created whenever an error generated by the database server. (Client-side errors are raised as standard common language runtime exceptions.) It always contains at least one instance of DB2®Error .
If the severity of the error is too great, the server can close the DB2Connection . If the server does close the connection, the application will need to open a new connection.
[Visual Basic, C#] The following example generates an DB2Exception due to a missing database, and then displays the exception.
[Visual Basic]
Public Sub ThrowDB2Exception()
Dim mySelectQuery As String = "SELECT column1 FROM table1"
Dim myConnection As New DB2Connection _
("DATABASE=BADDB;")
Dim myCommand As New DB2Command(mySelectQuery, myConnection)
Try
myCommand.Connection.Open()
Catch myException As DB2Exception
Dim i As Integer
For i = 0 To myException.Errors.Count - 1
MessageBox.Show("Index #" + i.ToString() + ControlChars.Cr _
+ "Message: " + myException.Errors(i).Message
+ ControlChars.Cr _
+ "Native: " + myException.Errors(i).NativeError.ToString()
+ ControlChars.Cr _
+ "Source: " + myException.Errors(i).Source + ControlChars.Cr _
+ "SQL: " + myException.Errors(i).SQLState + ControlChars.Cr)
Next i
End Try
End Sub
[C#]
public void ThrowDB2Exception()
{
string mySelectQuery = "SELECT column1 FROM table1";
DB2Connection myConnection =
new DB2Connection("DATABASE=BADDB;");
DB2Command myCommand = new DB2Command(mySelectQuery,myConnection);
try
{
myCommand.Connection.Open();
}
catch (DB2Exception myException)
{
for (int i=0; i < myException.Errors.Count; i++)
{
MessageBox.Show("Index #" + i + "\n" +
"Message: " + myException.Errors[i].Message + "\n" +
"Native: " + myException.Errors[i].NativeError.ToString() + "\n" +
"Source: " + myException.Errors[i].Source + "\n" +
"SQL: " + myException.Errors[i].SQLState + "\n");
}
}
}
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.