Exceptions in K2.net

  • 2 November 2005
  • 3 replies
  • 2 views

Badge +3
How does K2.net handle exceptions thrown by C# code?

Does an unhandled exception in a code block automatically call the Exceptions code that can be defined for the Event? Does an unhandled exception then precolate to the Activity and beyond?

How does one programatically call the Exceptions code block?

Any help, greatly appreciated.
David.

3 replies

Badge +9
Hi David,

K2.net will Bubble the error up from the level it occurred in to the closest Exception Handler available, lets look at the following example:

An error occurred in a Server Event , this is the lowest/deepest level that you have, it will work as follows:

If no exception handling is done in the event self K2.net will look at the

1. Event Exceptions
2. Activity Exceptions
3. Process Exceptions

If none was found in any of the Exceptions sections of the process you will find that K2.net Server will mark the process instance into error state and log an error under the error profiles in K2.net Service Manager. Please have a look at the K2.net Helpfiles under References -> K2.net 2003 Objects -> Namespaces -> Sourcecode.KO -> Classes -> Exception Context

I hope this is helpful
Badge +3
Thanks for that.

Following on, what's the recommended method of handling an unexpected exception in custom code?

For example, if the Server Event in threw an exception and the Exception block for the event reported the error by email to the support team. What happens to the workflow? Is it stuck at the Server Event? Would the support team be able to access the code causing the exception as they would if the exception wasn't handled?
Badge +11
That largely depends on where and how you handle your errors.

If you handle the exception in Event code with Try-Catch block:
* No error in error profiles
* Process continues
* If you need error to bubble-up, you need to throw another exception i.e. Throw New Exception("I don't know what to do with this exception", ex)

If you handle the exception in the Exception code block of Events, Activities or Processes:
* By default the error will end up in Error Profiles
* Process will stay in Error state.
* If you do NOT need the Error in Error Profiles and Process to continue, add the following line: K2.AddToErrorLog = False

Hope this helps,
Ockert

Reply