Changes between Version 21 and Version 22 of CodeBestPractices


Ignore:
Timestamp:
2012-12-01 11:02:37 (7 years ago)
Author:
jeroens
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CodeBestPractices

    v21 v22  
    44The following issues are discussed on this page: 
    55 * [#Robustness Robustness] 
    6    * [#try_/_cath Try / Catch and Assertions] 
     6   * [#try_/_cath Try / Catch] 
     7   * Logging errors 
    78   * Creation and disposal of objects and data 
    8    * Logging events 
    99 * [#Compatibility Cross-platform compatibility] 
    1010   * [#Mono Mono] 
     
    3030            Handles m_btnRun.Click 
    3131 
    32             Try 
     32            '''Try''' 
    3333                If Not Me.IsRunning Then 
    3434                    Me.m_iTimeSteps = Me.Core.nEcosimTimeSteps 
     
    3636                    Me.Core.RunEcoSim(AddressOf TimeStepFromEcoSim_handler, True) 
    3737                End If 
    38             Catch ex As Exception 
     38            '''Catch ex As Exception''' 
    3939                cLog.Write(ex, "form RunEcosim.OnRun") 
    40             End Try 
     40            '''End Try''' 
    4141 
    4242        End Sub 
     
    4747=== Logging events === 
    4848 
    49 The EwE Log file, created and managed by the core, and stored in the Windows application data folder, contains a track list of important actions taken by !EwE in response to user requests and a track record of failures and successes. The purpose of the log is to provide postmortem diagnostics when an error has occurred. You can use the log as well in your plug-ins. Frankly, we think you should, because  
     49The EwE Log file, created and managed by the core, and stored in the Windows application data folder, contains a track list of important actions taken by EwE in response to user requests and a track record of failures and successes. The purpose of the log is to provide postmortem diagnostics when an error has occurred. You can use the log as well in your plug-ins. Frankly, we think you should. 
     50 
     51If you strategically encapsulate [#try_/_cath Try / Catch] blocks, why not write the result of the exception to the log file: 
     52 
     53Take for instance the code that runs in response to a 'Run' button click on the Run Ecosim form: 
     54{{{ 
     55        Private Sub OnRun(ByVal sender As System.Object, ByVal e As System.EventArgs) _ 
     56            Handles m_btnRun.Click 
     57 
     58            Try 
     59                If Not Me.IsRunning Then 
     60                    Me.m_iTimeSteps = Me.Core.nEcosimTimeSteps 
     61                    Me.m_graph.Refresh() 
     62                    Me.Core.RunEcoSim(AddressOf TimeStepFromEcoSim_handler, True) 
     63                End If 
     64            Catch ex As Exception 
     65                '''cLog.Write(ex, "form RunEcosim.OnRun")''' 
     66            End Try 
     67 
     68        End Sub 
     69}}} 
    5070---- 
    5171