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
25
26
27
Quintiq file version 2.0
#parent: #root
Method AfterMethodCall_TryBlock (LibOpt_Task task, LibOpt_Run run, Boolean hasto_unregistertask)
{
  Description:
  [*
    This method should only be used within a `try{...}` block. To be more precise, it should be used after the `BeforeMethodCall_TryBlock` 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. 
    Since we are about to leave a `try{...}` block, the current transaction won't be safe anymore, so `this.EndSafeTransaction();` is called.
    Finally, 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.
    // AfterMethodCall_TryBlock should only be called from 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( run );  
    
    // We are about to leave a 'safe' `try{...}` block, so the 'IsSafe' method should return 'false' when it is called.
    // The 'EndSafeTransaction' resets the `TransactionGUID` attribute. This ensures that the 'IsSafe' method will return 'false' when it is called.
    this.EndSafeTransaction();
    
    this.UnregisterTask( task, hasto_unregistertask );
  *]
}