How to Manage Exception Handling in K2.net 2003 with SP4
KB000167
PRODUCT
Introduction
Enhancements to the error messaging in K2.net 2003 with SP4 and the error logging format now includes the error number along with the error message as a single text string. The following article describes the advantages of the enhancements and how to change custom code to manage the change.
The new exception format means that the string message generated changes from something expected for e.g. "Worklist item not found" to something similar for e.g. "6030 Worklist item not found". The inclusion of the error number in the message will cause a mismatch however; the advantage to the new format is that the error code provides a reliable reference to the exception and its cause.
Note: K2.net 2003 is delivered with a default list of error codes and messages for operational requirements. Developers would thereafter amend this resource as they choose. Refer to the K2.net 2003 Logging Framework documentation. |
For runtime purposes, the developer would therefore match the error number to identify a problem and not the entire message as before. This enhancement does affect backwards compatibility, but only if the custom code is not updated to trap the error code instead of the entire message. Applications looking for the customary pre K2.net 2003 SP4 format will start generating mismatches since the error number is now part of the error message.
In the two C# Samples shown below, the first sample demonstrates the common method applied with K2.net 2003 SP3. The second method demonstrates how to trap for the error number as part of the error message for application using K2.net 2003 with SP4.
C# Sample 1: Applies to service pack releases prior to K2.net 2003 with SP4
{
//SP3 Error Handling
//Worklist Item Not found
SourceCode.K2ROM.Connection oK2Connection = new SourceCode.K2ROM.Connection();
SourceCode.K2ROM.WorklistItem oWorklistItem;
try
{
oK2Connection.Open("w2003");
oWorklistItem = oK2Connection.OpenWorklistItem("1,1,1","ASP");
}
catch(Exception ex)
{
//Try to match entire error message
if(ex.Message == "Worklist item not found")
{
MessageBox.Show("Your work item is no longer available on the system. Please contact your system Administrator for more information.");
}
else
{
MessageBox.Show(ex.Message);
}
}
}
C# Sample 2: Applies to service pack release K2.net 2003 with SP4
{
//SP4 Error Handling
//6030 Worklist Item Not found
SourceCode.K2ROM.Connection oK2Connection = new SourceCode.K2ROM.Connection();
SourceCode.K2ROM.WorklistItem oWorklistItem;
try
{
oK2Connection.Open("w2003");
oWorklistItem = oK2Connection.OpenWorklistItem("1,1,1","ASP");
}
catch(Exception ex)
{
//Check for Error number 6030 at the start of the message
//Each K2.net Error message will contain the error number at the start of the message
if(ex.Message.IndexOf("6030")==0)
{
MessageBox.Show("Your work item is no longer available on the system. Please contact your system Administrator for more information.");
}
else
{
MessageBox.Show(ex.Message);
}
}
}
}