Skip to main content
How can one obtain the Error Item Name (as shown in the Repair Error dialog) in exception handler code (that is, from an ExceptionContext)?

Thank you!
Remarks
The Exception part of a process allows developers to handle exceptions that may occur during execution of the process instance. Depending on the severity of the exception developers can correct the issue using some custom code before continuing with the process execution or force K2.net Server to log an error in the error profile. All errors logged in the error profile require user interaction allowing K2.net Administrators to repair the error using K2.net Service Manager.

K2.AddToErrorLog = True will cause K2.net Server to log the error to the error log, the process execution will only continue once the error has been repaired using the K2.net Service Manager.
K2.AddToErrorLog = False assumes that the error has been handled by custom code in the Exception part of the process. Only use this option if the error has been handled and will not cause other exceptions within the process instance.

Example
[Visual Basic]

Sub Main (ByVal K2 As ExceptionContext)
Dim MyKOProcessInstance As ProcessInstance
Dim MyErrObject As Object

MyKOProcessInstance = K2.ProcessInstance
MyErrObject = K2.ExceptionObject

If K2.ContextType = ContextType.ClientEvent Then
K2.AddToErrorLog = True
K2.AddToServerLog = True
ElseIf K2.ContextType = ContextType.DestinationRule Then
K2.AddToErrorLog = True
ElseIf K2.ContextType = ContextType.EscalationAction Then
K2.AddToErrorLog = True
ElseIf K2.ContextType = ContextType.EscalationRule Then
K2.AddToErrorLog = True
ElseIf K2.ContextType = ContextType.IPCEvent Then
K2.AddToErrorLog = True
ElseIf K2.ContextType = ContextType.LineRule Then
K2.AddToErrorLog = True
ElseIf K2.ContextType = ContextType.PrecedingRule Then
K2.AddToErrorLog = True
ElseIf K2.ContextType = ContextType.ServerEvent Then
K2.AddToErrorLog = False
Dim MyMail As System.Web.Mail.SmtpMail
Dim MyMailMessage As New System.Web.Mail.MailMessage()
Dim MyMessage As Object
Dim MyErrorMessage As String
Dim MyDate As System.DateTime

MyMailMessage.From = MyKOProcessInstance.DataFields("MyMail").Value
MyMailMessage.To = MyKOProcessInstance.DataFields("MyMail").Value
MyMailMessage.Subject = "Server event exception by the K2.net Server."
MyMailMessage.Body = MyErrObject.ToString
MyMailMessage.BodyFormat = 0
MyMail.Send(MyMailMessage)
MyMail = Nothing
ElseIf K2.ContextType = ContextType.StartRule Then
K2.AddToErrorLog = True
ElseIf K2.ContextType = ContextType.SucceedingRule Then
K2.AddToErrorLog = True
End If
End Sub


[C#]
.Value.ToString(); 
MyMailMessage.Subject = "Server event exception by the K2.net Server.";
MyMailMessage.Body = MyErrObject.ToString();
MyMailMessage.BodyFormat = 0;
System.Web.Mail.SmtpMail.Send(MyMailMessage);
break;
case (ContextType.StartRule):
K2.AddToErrorLog = true;
break;
case (ContextType.SucceedingRule):
K2.AddToErrorLog = true;
break;
}
}


Hope this helps.
icon-quote.gifdavid:

The Exception part of a process allows developers to handle exceptions that may occur during execution of the process instance.


This does not address my question.

Go into K2.net 2003 Service Manager, and select an Error Profile. Right-click and choose Properties. This will open the Repair Error dialog. One of the items in this dialog is called Error Item Name, and contains the name of the event (or other item) where the error occurred. I would like to retrieve this data within exception handling code.

Incidentally, the example exception code from the help file is unnecessarily verbose. Setting AddToErrorLog to true does not appear to be necessary - adding to the error log and placing the process in an error state is the default behavior, even if an exception handler exists. Also, several of the ContextTypes checked (IPCEvent and EscalationRule, at least) are irrelevant - exceptions in those contexts will never fire custom exception code (at least in the current version of K2). Hopefully that will be corrected in a future version.

Reply