Exception Handling in k2

  • 2 August 2004
  • 2 replies
  • 0 views

Badge
I want to know the various ways of exception handling that can be done in k2. Please give me a clear picture of Exception handling at Process Level and also at Activity Level.

2 replies

Badge +1
I too have a query regarding exception handling in K2.

I have an activity to which I have added a server event which can throw an exception. I have placed exception handling code both at activity level and event level, yet it never seems to get executed for some reason.
The exception is definitely being thrown as I can see the appropriate error log in the Error Profiles within the Service Manager.

Has anyone else experienced this problem and if so, is there a workaround?

Thanks in advance,

Paul.
Badge +1
Hi Paul,
I wanted to receive notification when an exception was thrown in my process. I was able to add the following code to the exception handler at the process level. I'm not sure if that is granular enough handling for your scenario, but it may be worth a shot. HTH, Scott.


public void Main(ExceptionContext K2)
{
System.Web.Mail.MailMessage objMsg = new System.Web.Mail.MailMessage();
string strFrom = "";
string strEmail = "";
string strSubject = "";
string strBody = "";

System.Web.Mail.SmtpMail.SmtpServer = SourceCode.K2Utilities.GeneralMod.GetDefaultSMTPServer();

//add to string table to make a little more robust
strFrom = "myprocess@company.com";
strEmail = "supportperson@company.com";

//provide basic error info
strSubject = "An Error has occurred in K2 Process: " + K2.ProcessInstance.Process.Name;
strBody = "Error Date: " + System.DateTime.Now.ToString() +
Environment.NewLine +
"Error Process: " + K2.ProcessInstance.Process.Name +
Environment.NewLine +
"Error Item Name: " + K2.ContextType.ToString() + Environment.NewLine;

//package up email
objMsg.From = strFrom;
objMsg.To = strEmail;
objMsg.Subject = strSubject;
objMsg.Body = strBody;

//send the mail
System.Web.Mail.SmtpMail.Send(objMsg);

}

Reply