Skip to main content

Hi

I use K2 Designer for Visual Studio.

I create an Activity with a Server event. I want to catch exception of this event. In the server event wizard i check "Enable Exception Rule" and click on View Code. I see a Workflow, right click and View Code. I add my code : set a datafield

 

    public partial class Exception_36d6348add684e9f82f7b6ebbccea099 : IWorkflowContext<HostContext>
    {

        #region - K2 Context -
        private HostContext _K2;
        xEditorBrowsable(EditorBrowsableState.Never)]
        eDesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public HostContext K2
        {
            get { return _K2; }
            set { _K2 = value; }
        }
        #endregion

        #region - Properties_ExecuteCode -
        private void Properties_ExecuteCode(object sender, EventArgs e)
        {
            K2.ProcessInstance.DataFieldse"IsException"].Value = true;

            K2.AddToErrorLog = K2.Configuration.IsErrorLog;
            K2.AddToServerLog = K2.Configuration.IsServerLog;
        }
        #endregion

    }
 

 

But when i execute my workflow, exception is not caught. My workflow has error status.

So my question is how can i signify that i catch exception and treat it ? 

Thank for your replies 

This is weird, didnt the exception set the value of the datafield to true as per your code?


Hi Yousef

My datafield equals true but my workflow status is error. I want it to be "active" because I handle my exception.


Then I think you need to disable exception handeling, and on your server event, write a try-catch block where you expect exception and silently do what you want.


Enabling exceptions will definitly put the instance in error state.


hope this helps.


ok i will propably use this method with my server event but with a smart object event how can i handle my exception ?

Is it when executing a method of a smartobject? guess it would be the same... but not really sure.

I'd think that at any time you have unhandled exception or handled but with a throw ex, it will cause the workitem to go into Error mode.

If you simply have this then it will not error but you are hiding the true error.

try

   x = 0 / 0

catch

    'do nothing

end try


Hi,


I have an activity which consists of several server events (C# code). Let's call them Event A, Event B, Event C. I have wrapped the code with try-catch block in all the server events and will throw exception whenever I catch any exception while calling my wrapper code (reference dll). Let's say Event C has hit an exception; if I retry from the management console > Error Profile, would K2 reexecute Event A and B as well? I only want to retry from the point of failure onwards.


Thanks.


K2 retries from the code from the event at which it failed.  So in your example it would re-execute the code in Event C if you clicked on retry.  It would not re-execute Event A and Event B.


Note that it would re-execute the entire code in Event C.  It doesn't just just retry the line that generated the error which could have implications depending on what your server event code is actually doing.


For example after the retry the ServerEvent2 datafield value would be the datetime of the retry and not the datetime when the first error occurred. 


             try
            {
                K2.ProcessInstance.DataFieldsÂ"ServerEvent2"].Value = DateTime.Now.ToString();
                int x = 0;
                int y = 1;
                int z = y / x;




                K2.ProcessInstance.DataFields "ServerEvent2"].Value = "test";
            }
            catch (Exception ex)
            {
                throw ex;
            }




Thanks, Tim.


Reply