lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Quintiq file version 2.0
#parent: #root
Method HandleQuillError (QuillError e)
{
  Description:
  [*
    This method can be found within onerror and onfinalize blocks.
    
    When a `QuillError` is caught we call the `HandleQuillError` method on all components that were executed in the current Quill transaction.
    Only the last component (the one that caused the error) will be called with the actual `QuillError`, the others will receive a null instance.
    
    Then we make sure to undo the transaction. Since we caught an error in a try-block, the dataset may be in an incorrect state.
    By making sure we always rollback the transaction after a rollback we can make sure that we don't end up in an incorrect dataset state.
  *]
  TextBody:
  [*
    // Handle Quill errors for all tasks
    task := this.GetTask();
    
    run := task.Run();
    if( run.IsFinalizingTask() or run.InOneTransaction() )
    {
      run.IsFailed( true );
    }
    
    if( not isnull( task ) )
    {
      component := task.Component();
      component.HandleQuillError( task, e );
      LibOpt_DatasetCopyConditional::CopyDatasetConditionally( LibOpt_Component::ComponentPosition_Error(), task, true ); 
    
      // If component X is linked to a previous component by using a TaskTransporterOneTransaction, then DoFinalize is not called when an error occurs during the execution of component X.
      // Therefore, all dataset copies that are created before an error is thrown are handled here instead of in LibOpt_DatasetCopyConditional::DoFinalizeDataset
      LibOpt_DatasetCopyConditional::DoFinalizeDatasetCopyDelete( task, true );  
      // Convert all memory-only datasets that are not deleted to standalone datasets.
      LibOpt_DatasetCopyConditional::DoFinalizeDatasetCopyChangeToStandAlone( task );
      
      task := task.PreviousTaskOnCurrentTransaction();
    }
    
    while( not isnull( task ) )
    {
      component := task.Component();
      component.HandleQuillError( task, null( QuillError ) );
    
      LibOpt_DatasetCopyConditional::DoFinalizeDatasetCopyDelete( task, true );  
      LibOpt_DatasetCopyConditional::DoFinalizeDatasetCopyChangeToStandAlone( task );
      
      task := task.PreviousTaskOnCurrentTransaction();  
    }
    
    // Rollback the transaction
    this.Rollback( Translations::LibOpt_Optimization_CapturedException(), e );
  *]
  InterfaceProperties { Accessibility: 'Protected' }
}