Please enable JavaScript to view this site.

 

Navigation: Macros > Macro Language > Instructions

User-Defined Messages and Errors

Scroll Prev Up Next More

Sometimes, you may want to generate your own messages and/or errors in response to specific conditions that can only be evaluated at run-time.

 

The macro functions that allow you to write instructions to generate your own messages or errors are:

 

Assert

Generates an error, with the message of your choice, if a given condition is not true.

// check if the supplied month number is valid
Assert(nMonthNumber in [1..12], 'Month numbers are 1-12', true)
// if we get to here then we are good

This is useful at places in macro code where you might think "if we are here then this condition must be true". Assertions ensure that this is verified or that an error is generated.

 

Depending on the value of the last parameter (true, in the above example), the generated error can cause only the current macro to abort and generate a run-time message similar to a token error (listed in the diary generation messages dialog), or it can cause the entire diary generation to abort.

LogMessage

Generates a run-time message but does not affect the execution of the macro otherwise.

// look for all holidays on same date
while FindNextHolidayOnDate(nRunDate, nCurHolSet)
    sHolidayName = GetHolNameFromTable(false)
    LogMessage('Processing holiday: ' + sHolidayName)
    // process the holiday
    // ...
endwhile

These log messages are then included the diary generation messages dialog.

RaiseError

Generates an error with the message text of your choice.

switch nWeekdayNumber
   case 1..5
      // do weekday stuff
   case 6..7
      // do weekend stuff
   else
      RaiseError('nWeekdayNumber is not in range of 1-7', true)
endswitch

Depending on the value of the last parameter (true, in the above example), the generated error can cause only the current macro to abort and generate a run-time message similar to a token error (listed in the diary generation messages dialog), or it can cause the entire diary generation to abort.

 

For more details on these 3 functions, click on their respective links, in the left column, above.

 


Topic 174300, last updated on 19-Apr-2020