Error Reporting

  • 29 November 2006
  • 5 replies
  • 0 views

Badge +7
Hi All,

Does anyone know a way to automatically report errors in Service Manager error profiles?

We had an issue recently where one process instance entered an error state - but didn't notice until we manually went and checked the error profile.

It would be great if someone knew an easy way to report errors, say via email, when they happen.

Failing that, does anyone know which table in the DB holds the error profiles? At least that way I could set up a data view on it and put it onto a sharepoint dashboard or something.

Many thanks in advance, Rich

5 replies

Badge +8
This reply may be of limited use to you at this stage, but you can implement exception handling on event, activity or process level to catch any exception thrown during process execution and to perform some action upon the error. The problem here is that you need to apply the change and re-export your processes, so existing process instances will not be aware of the error handling, and the other issue is that exceptions thrown outside of executing processes will not be handled by the same error handling.

Generally, you should implement the exception handling logic on process level in order to cover the process in it's entirety. You can then handle specific activities or events with specialized error handling, if required.

FWIW, here are some code samples...

Send email upon error:
.ToString();
System.Web.Mail.SmtpMail.Send(objMsg);

//throw an expection to put the process into error state
throw new ApplicationException(K2.ExceptionObject.ToString());
}


Add entry to event log upon error:

public void Main (ExceptionContext K2)
{
//do not add to error log yet - execute execption handling code first
K2.AddToErrorLog = false;

// Build error message string
string strErrorMessage = @"An exception was thrown during execution of a K2 workflow." + System.Environment.NewLine +
"This process instance is now in an error state." + System.Environment.NewLine +
"The details of the exception are listed below." + System.Environment.NewLine + System.Environment.NewLine;
// Process Name...
strErrorMessage += "Process Name: " + K2.ProcessInstance.Process.Name + System.Environment.NewLine;
// Process Folio...
strErrorMessage += "Process Folio: " + K2.ProcessInstance.Folio + System.Environment.NewLine;
// Process ID...
strErrorMessage += "Process ID: " + K2.ProcessInstance.ID + System.Environment.NewLine;
// Date...
strErrorMessage += "Error Date and Time: " + System.DateTime.Now.ToString()+ System.Environment.NewLine + System.Environment.NewLine;
// Exception object...
strErrorMessage += "Exception thrown: " + System.Environment.NewLine + K2.ExceptionObject.ToString();

//write to event log
System.Diagnostics.EventLog oEV = new System.Diagnostics.EventLog();
oEV.Source = "K2 Process";
oEV.WriteEntry(strErrorMessage,System.Diagnostics.EventLogEntryType.Error);

//throw an expection to put the process into error state
throw new ApplicationException(K2.ExceptionObject.ToString());
}
Badge +7
Thanks Neil, that's great stuff :D

Your reply is still of a lot of use - let me explain the situation:

Once the user starts the process, it proceeds through several activities that perform a lot of data manipulation and write various datafields and xml fields to a SQL table. Because of a breakdown in communication (the initial form wasn't validated for length of entry on an item, and the database column was of a limited size) about 50% of the processes fired through it didn't get to the next client event. It was simple to fix the DB problem and then repair the error.

But my question was really because I don't want this to occur again - we didn't realise the issue until the phones started ringing!

How might I best go about implementing some of your ideas? Is it something that I would have to attach to individual events - or can I make the code cover the process as a whole, so as soon as it goes into an error state at any point, I receieve an email?

I don't have a great understanding of error handling in K2. If I'm missing something in the documentation or knowledge base :oops: please feel free to just point me in the right direction :D

Many thanks again, Richard
Badge +7
Ok I guess I just need new glasses 8)

In my process properties I can edit the code for exceptions... So presumably this covers all exceptions thrown by the process?

EDIT: Works like a charm - thanks again Neil

Many thanks, Richard
Badge +8
no problem. There is some information on handling exceptions in the help file as well as the knowledge base - just do a search for 'exception' or 'error'.

Is it something that I would have to attach to individual events - or can I make the code cover the process as a whole, so as soon as it goes into an error state at any point, I receive an email?

I would recommend that you have a generic error handler on process level. To add one, open the solution in K2 Studio, right-click on the process name in the solution explorer and select 'properties'. Select the 'exceptions' sub-heading and then click on 'Edit Code'. You can then paste the code samples I've posted in this code window. You will need to export the process again and as I had stated earlier, any currently running process instances will not know about this error handling - it will only be applied to new process instances.

Note that in my email code sample, I used String Table entries to specify the 'from' and 'to' addresses - you can also hardcode them but with using string table entries you can update the addresses as required and error notification will be sent to the relevant person.

If you like, you can then add more specific error handling for specific activities and events - maybe you can have a event handler for the SQL event to retry the code or take some other action - it's up to you. The concept of handling the exception handling stays the same, though.

So presumably this covers all exceptions thrown by the process

Yes, and you can have different error handling for different processes. Unfortunately it will not handle errors thrown outside of a process instance (the famous 'a database error has occurred' on K2 server startup error, for example, but typically you'll know about these errors right away anyway :)

EDITED to spell exception correctly :oops:
Badge +13
How do I bubble up my exception msg from my events/module with these info:

Throw New Exception("Error in function xyz: " & ex.GetBaseException.Message.ToString() & vbCrLf & "StackTrace: " & ex.GetBaseException.StackTrace

I do not see my message in K2.ExceptionObject.ToString in the Process level exception handler.

Reply