yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Quintiq file version 2.0
#parent: #root
Method AfterMethodCall_ExistingSafeTransaction (LibOpt_Task task, Boolean hasto_unregistertask)
{
  Description:
  [*
    This method should only be used if the `IsSafe` method returns `true`. If the `IsSafe` method returns `false`, then a new safe transaction should be started first by using a `try{...}` block. 
    This method should be called after the `BeforeMethodCall_ExistingSafeTransaction` method and some method that could throw errors are called. 
    The method will first try to force any propagation errors (if they exist), so that these propagation errors are nicely handled. In particular, these errors should show up as a child of the `LibOpt_Task.SnapshotComponent` snapshot in the 'Snapshots' form. 
    The `LibOpt_Task` is unregistered from the `LibOpt_CurrentTransaction`. By unregistering the `LibOpt_Task`, we ensure that any errors in future `LibOpt_Tasks` won't show up as a child of the `LibOpt_Task.SnapshotComponent` snapshot.
  *]
  TextBody:
  [*
    // A propagation issue might have been introduced since the previous time 'PropagateToFindPropagationErrors' was called.
    // If this is the case, then calling 'PropagateToFindPropagationErrors' will result in a propagation error.
    // The 'AfterMethodCall_ExistingSafeTransaction' method should only be called if the current transaction is 'safe'. A transaction is safe when transaction.IsSafe() is true. 
    // When transaction.IsSafe() is true, then we are inside some try{...}onerror{...} block. Therefore, the propagation error is handled gracefully.
    // When an error occurs, a LibOpt_SnapshotError is created and placed under the component of the last registered task. (Which is why we call 'PropagateToFindPropagationErrors' before calling 'this.UnregisterTask( task )').
    // Automatic propagation is disabled by default. It can be enabled in the context menu of the Optimizer and Run forms
    LibOpt_CurrentTransaction::PropagateToFindPropagationErrors( task.Run() );  
    
    this.UnregisterTask( task, hasto_unregistertask );
  *]
}