dgException class | QSYS API Reference Guide
Estimated reading time: 11 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. |
dgException()
Initializes a new instance of the dgException class.
dgException()
dgException(String)
Initializes a new instance of the dgException class with a specified error message.
dgException(String)
Parameters
Type | Parameter name | Description |
---|---|---|
String | message | The message that describes the error. |
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(String, Exception)
Parameters
Type | Parameter name | Description |
---|---|---|
String | message | The error message that explains the reason for the exception. |
Exception | inner | The exception that is the cause of the current exception, or a null reference if no inner exception is specified. |
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, Exception)
Parameters
Type | Parameter name | Description |
---|---|---|
dgErrorNumber | error | The error code. |
Int32 | systemError | The system error code. |
dgErrorClass | errorClass | The class of the error. |
String | message | The error message. |
String | text | The error text. |
Exception | inner | The inner exception. |
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, Int32, dgErrorClass, String, String)
Parameters
Type | Parameter name | Description |
---|---|---|
dgErrorNumber | error | The error code. |
Int32 | systemError | The system error code. |
dgErrorClass | errorClass | The class of the error. |
String | message | The error message. |
String | text | The error text. |
dgException(dgErrorNumber)
Create a dgException with the passed error code.
dgException(dgErrorNumber)
Parameters
Type | Parameter name | Description |
---|---|---|
dgErrorNumber | error | The error code. |
dgException(dgErrorNumber, Exception)
Create a dgException with the passed error code and exception.
dgException(dgErrorNumber, Exception)
Parameters
Type | Parameter name | Description |
---|---|---|
dgErrorNumber | error | The error code. |
Exception | e | The Exception object. |
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. |
string FormatMessage(IFormatProvider provider, string msg)
Formats the error message into a single string for logging or displaying to the user.
string FormatMessage(IFormatProvider provider, string msg)
Parameters
Type | Parameter name | Description |
---|---|---|
IFormatProvider | provider | An object that supplies culture-specific formatting information. |
String | msg | The error message. |
Returns
Type | Description |
---|---|
String | A formatted string containing the error message. |
dgErrorClass GetDefaultErrorClass(dgErrorNumber err)
Each dgErrorNumber has a default associated dgErrorClass. Thismethod returns it.
dgErrorClass GetDefaultErrorClass(dgErrorNumber err)
Parameters
Type | Parameter name | Description |
---|---|---|
dgErrorNumber |
Returns
Type | Description |
---|---|
dgErrorClass |
string 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.
string GetVerboseText()
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 = new AdgConnection("*Public/DG NET Local");
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 = new AdgConnection("*Public/DG NET Local");
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 = new AdgConnection("*Public/DG NET Local");
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();