I have been working on WF recently and have encountered some problems and experiences to share with you and discuss them. This issue focuses on exception handling.
As far as I know, in WF, once a process instance is started, whether it is running correctly or wrong, whether it is a systemic error or a business error, the instance status is eventually migrated to the closed status and serialized. Of course, an error, cancellation, or compensatory event may occur.
In this way, there will be a major problem, that is
Some exceptions can be manually corrected. The extreme example is in the debugging process. However, WF enters the preset error handling process no matter what the situation, and closes the instance at the end, so that once an exception occurs, even if I fix the problem, I have to try again, this is a headache for me.
What I need is that, in some cases, exceptions can be rectified and re-transmitted. The instance data will not be saved or compensated; in some cases, the current WF processing method is required.
So what if it is implemented?
My approach is to establish an independent Exception Handling Mechanism to differentiate the WF preset methods. Both methods coexist.
The procedure is as follows:
1. I have created the exception attribute in the base class of all activities as the runtime attribute;
2. When an exception can be corrected again (whether systemic or business), set this attribute and immediately close the activity;
3. When its parent activity detects that its exception attribute is assigned a value, it also closes itself until the root activity;
4. the serialization service starts. You must customize the serialization service and check whether the exception attribute of the root activity is assigned a value in the SAVE method. If yes, the serialization action is ignored, and record exceptions.
The above implementation method is very simple and flexible, but if you use the default WF hierarchical activity, the exception transmission will be very difficult, and the previous linear method will be used, you only need to pass a layer.
PS: another problem with this method is that you need to add try to all methods... catch quickly captures exceptions and sets the basic class attributes. Otherwise, the WF preset mode will still be used. This is a headache. If someone knows how to avoid this, please kindly advise. Thank you!