dgException class
Estimated reading time: 7 minutes
The dgException class is a custom exception class that extends the base Exception class. It provides additional functionality for handling errors specific to the application.
Namespace: ASNA.DataGate.Common Assembly: ASNA.QSys.DataGate.Client.dll
Inheritance: Object –> Exception
Thread Safety
Any public static (Shared) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
Constructors
| Name | Description |
|---|---|
| dgException() | Initializes a new instance of the dgException class. |
| dgException(String) | Initializes a new instance of the dgException class with a specified error message. |
| dgException(String, Exception) | Initializes a new instance of the dgException class with a specified error message and a reference to the inner exception that is the cause of this exception. |
| dgException(dgErrorNumber, Int32, dgErrorClass, String, String, Exception) | Create a dgException with the passed error code, system error code,error class, and text. This dgException is constructed and thrownwhen the database server program returns an error. |
| dgException(dgErrorNumber, Int32, dgErrorClass, String, String) | Create a dgException with the passed error code, system error code,error class, and text. This dgException is constructed and thrownwhen the database server program returns an error. |
| dgException(dgErrorNumber) | Create a dgException with the passed error code. |
| dgException(dgErrorNumber, Exception) | Create a dgException with the passed error code and exception. |
Properties
| Type | Name | Description |
|---|---|---|
| dgErrorClass | DefaultErrorClass | Gets or sets the default error class. This property is used to categorize the type of error that occurred. |
| dgErrorNumber | Error | The error code for this dgException. For server side errors, thisis the error code returned by the server following a databasetransaction. |
| dgErrorClass | ErrorClass | The error class for this dgException. This categorizes the type of error that occurred. |
| String | Message | Gets a message that describes the current exception. This property is overridden to provide custom error messages. |
| Int32 | SystemError | The system error code, if any for this dgException. This memberwill contain meaningful information only with the value ofErrorClass is one of the following: |
| String | Text | The text message for this dgException. This provides additional details about the error. |
Methods
| Signature | Description |
|---|---|
| FormatMessage(IFormatProvider, String) | Formats the error message into a single string for logging or displaying to the user. |
| GetDefaultErrorClass(dgErrorNumber) | Each dgErrorNumber has a default associated dgErrorClass. Thismethod returns it. |
| GetVerboseText() | Return a string containing a verbose description of thedgException. This string will most likely contain line separatorcharacters. All dgException member variables are included in thestring. |
Examples
Several of the following examples create an AdgConnection by calling the createAdgConnection() method which is part of the AdgConnection Example showing how to new an AdgConnection using a Database Source Profile Name.
Example 1. dgException ErrorClass and SystemError properties example.
/* This code attempts to open a file exclusively.
* If it fails, we print out the IBM i exception responsible.
* "dbFile" is of type FileAdapter. */
dbFile.AccessMode = AccessMode.Write;
dbFile.OpenAttributes.ShareTypes = ShareTypes.Exclusive;
dbFile.OpenAttributes.WaitForFile = 0;
AdgDataSet dataSet = null;
try
{
dbFile.Open(dataSet);
}
catch(dgException dgEx)
{
/* Take special action if error is due to the IBM i exception
* "CPF1002". */
if (dgEx.ErrorClass == dgErrorClass.dgEC_AS400CPF &&
dgEx.SystemError.ToString("X") == "1002")
{
MessageBox.Show("iSeries threw exception CPF1002.");
// Take alternative action here.
}
else
{
/* Throw exception otherwise. */
throw dgEx;
}
}
Example 2. dgException Message property example.
AdgConnection db = createAdgConnection("MyLocalDB");
FileAdapter dbFile = new FileAdapter(db, "*Libl/CMASTNEWL1", "CMMASTERL1");
dbFile.AccessMode = AccessMode.Read;
AdgDataSet myDS = null;
try
{
dbFile.OpenNewAdgDataSet(out myDS);
}
catch(dgException dgEx)
{
/* This will show a somewhat specific message as to what
* went wrong opening the file. */
MessageBox.Show(dgEx.Message, "Error opening file");
//Exit procedure here.
}
Example 3. GetVerboseText method example.
/* Verbose text generates a large string which is a concatanation
* of several of dgException's properties and also shows the
* stack trace. While not very user friendly, it can come in handy
* developing a program. */
AdgConnection db = createAdgConnection("MyLocalDB");
FileAdapter dbFile = new FileAdapter(db, "*Libl/CMASTNEWL1", "CMMASTERL1");
dbFile.AccessMode = AccessMode.Read ;
AdgDataSet myDS = null;
dbFile.OpenNewAdgDataSet(out myDS);
/* We retrieve the record for customer number 7800. */
AdgKeyTable keyTbl = myDS.NewKeyTable("RCMMASTL1");
keyTbl.Row["CMCUSTNO"] = 7800;
try
{
dbFile.ReadRandomKey(myDS, ReadRandomMode.Equal, LockRequest.Write, keyTbl);
myDS.ActiveRow["CMCUSTNO"] = 300;
dbFile.ChangeCurrent(myDS);
}
catch(dgException dgEx)
{ /* Print out Verbose text to figure out why ReadRandomKey is
* throwing an exception. */
MessageBox.Show(dgEx.GetVerboseText(), "Datagate Exception");
}
dbFile.Close();
db.Close();
Example 4. dgErrorNumber property example.
AdgConnection db = createAdgConnection("MyLocalDB");
FileAdapter dbFile = new FileAdapter(db, "*Libl/CMMASTERL1", "CMMASTERL1");
dbFile.AccessMode = AccessMode.Read;
AdgDataSet myDS = null;
try
{
dbFile.OpenNewAdgDataSet(out myDS);
}
catch(dgException dgEx)
{
/* There are many reasons why opening a file can fail. Here, we
* catch some of the more general ones. */
if (dgEx.Error == dgErrorNumber.dgEmMNOTFND)
MessageBox.Show("Member " + dbFile.MemberName + " not found!", "Error opening file");
else if (dgEx.Error == dgErrorNumber.dgEmFNOTFND)
MessageBox.Show("File " + dbFile.FileName + " not found!", "Error opening file");
else
MessageBox.Show(dgEx.Message, "Error opening file");
//Exit procedure here.
}
/* Do some action here. */
dbFile.Close();
db.Close();